Java Boot DOS command gather information note one
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
Import java.util.ArrayList;
Import java.util.List;
Import Org.testng.annotations.Test;
public class Person {
@Test//Use testng as the entrance
public void Doscmd () throws Interruptedexception
{
System.out.println (system.getproperty ("OS Name")); Judging the current system
Person p = new person ();
list<string> DL = p.excmd ("adb devices"); Calling the function to execute the ADB devices command
System.out.println (Dl.size ());
for (String s:dl) {//through enhanced for loop output content. s--defining variables, dl--for ADB devices content
System.out.println (s); Output display
}
}
Public list<string> excmd (String cmdstring) throws Interruptedexception {
list<string> doscmd = new arraylist<string> (); Define a list collection
process process = NULL; Set a process ID number
try {
Process = Runtime.getruntime (). exec (cmdstring); Start the EXEC command with built-in functions
InputStream in = Process.getinputstream (); Output stream through output
BufferedReader InR = new Java.io.BufferedReader (new InputStreamReader (in));
String line = null;
while (line = Inr.readline ()) = null)//through while traversing command lines information
{
Doscmd.add (line);
}
System.out.println ("successfully removed");
} catch (IOException e) {
SYSTEM.OUT.PRINTLN ("Data cannot be obtained");
E.printstacktrace ();
}
process.waitfor ();
Process.destroy ();
return doscmd;
}
This article is from the "Know the Ming" blog, please be sure to keep this source http://357712148.blog.51cto.com/6440370/1981485
Java Boot DOS command collection note one