1. java調用第三方應用使用 ProcessBuilder 對象來調用 java
例子位置:ui
xc-service-manage-media-processor/test/TestProcessBuilder命令行
//建立processBuilder對象 ProcessBuilder processBuilder = new ProcessBuilder(); //設置第三方應用程序的命令 // processBuilder.command("ping","127.0.0.1"); processBuilder.command("ipconfig"); //將標準輸入流和錯誤流合併 processBuilder.redirectErrorStream(true); //啓動一個進程(至關於在命令行中輸入命令) Process process = processBuilder.start(); //經過標準輸入流來拿到正常和錯誤的信息 InputStream inputStream = process.getInputStream(); //轉成字符流 InputStreamReader reader = new InputStreamReader(inputStream,"gbk"); //緩衝 char[] chars = new char[1024]; int len = -1; while ((len = reader.read(chars))!=-1){ String string = new String(chars,0,len); System.out.println(string); } inputStream.close(); reader.close();