我想知道如何知道 Busybox 的版本。搜索互联网我发现了这段代码:
public void busybox()throws IOException
{
/*
* If the busybox process is created successfully,
* then IOException won't be thrown. To get the
* busybox version, we must read the output of the command
*
*/
TextView z = (TextView)findViewById(R.id.busyboxid);
String line=null;char n[]=null;
try
{
Process p =Runtime.getRuntime().exec("busybox");
InputStream a = p.getInputStream();
InputStreamReader read = new InputStreamReader(a);
BufferedReader in = new BufferedReader(read);
/*
* Labeled while loop so that the while loop
* can be directly broken from the nested for.
*
*/
abc :while((line=in.readLine())!=null)
{
n=line.toCharArray();
for(char c:n)
{
/*
* This nested for loop checks if
* the read output contains a digit (number),
* because the expected output is -
* "BusyBox V1.xx". Just to make sure that
* the busybox version is read correctly.
*/
if(Character.isDigit(c))
{
break abc;//Once a digit is found, terminate both loops.
}
}
}
z.setText("BUSYBOX INSTALLED - " + line);
}
但返回的输出过于详细。我对细节感兴趣,只有版本,例如 1.21.1。我能怎么做?