1.java execute cmd command and get output result
1 ImportJava.io.BufferedReader;2 ImportJava.io.InputStreamReader;3 4 ImportOrg.apache.commons.lang3.text.StrBuilder;5 6 /**7 *8 * @authorUser19 */Ten Public classDeleteprogram { One Public Static voidrun () { ARuntime runtime =runtime.getruntime (); - Try { -BufferedReader br =NewBufferedReader (NewInputStreamReader (runtime.exec ("ipconfig"). getInputStream ())); the //StringBuffer B = new StringBuffer (); -String line=NULL; -StringBuffer b=NewStringBuffer (); - while((Line=br.readline ())! =NULL) { +B.append (line+ "\ n"); - } + System.out.println (b.tostring ()); A}Catch(Exception e) { at e.printstacktrace (); - } - - } - - Public Static voidMain (string[] args) { inDeleteprogram Delp =NewDeleteprogram (); - Delp.run (); to } + -}
2. Get the fields you need
Public Staticstring Getbackage (string path) {Process p; //the command in Test.bat is Ipconfig/allString cmd = "aapt dump badging" +path;//String cmd= "Jarsigner-verify-verbose-certs c:\\users\\administrator\\desktop\\pandaclient.apk"; String ResultStr =NULL; Try { //Execute Commandp =runtime.getruntime (). exec (CMD); //the output stream that obtains the command resultInputStream fis=P.getinputstream (); //read with a read output stream class//read rows with buffersBufferedReader br=NewBufferedReader (NewInputStreamReader (FIS, "GB2312")); String Line=NULL; //until you're done reading . inti = 0; while((Line=br.readline ())! =NULL) { if(Line.contains ("package:")) {//parse the content that meets your needs, and then return directly. ResultStr=Line ; Break; }//Resultstr=line;i++; } } Catch(IOException e) {e.printstacktrace (); } returnResultStr;}
1 Public Static void Main (string[] args) {2 String url= "www.taobao.com"; 3 String response=null; 4 response=getsingle (URL); 5 6 System.out.println (response); 7 }
Java executes cmd command and gets output result