Java 過程履行內部法式形成壅塞的一種緣由。本站提示廣大學習愛好者:(Java 過程履行內部法式形成壅塞的一種緣由)文章只能為提供參考,不一定能成為您想要的結果。以下是Java 過程履行內部法式形成壅塞的一種緣由正文
/**
* pdf轉swf函數
* @param path 輸出輸入文件途徑
* @param inputFileName 輸出文件名
* @param outputFileName 輸入文件名
* @return File 生成的swf文件
*/
private static File toSwf(String sourceFile, String destFile, String command) {
long beginTime = System.nanoTime();
Runtime rt = Runtime.getRuntime();
try {
Process process = rt.exec(command);
final InputStream isNormal = process.getInputStream();
new Thread(new Runnable() {
public void run() {
BufferedReader br = new BufferedReader(new InputStreamReader(isNormal));
StringBuilder buf = new StringBuilder();
String line = null;
try {
while((line = br.readLine()) != null){
buf.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("輸入成果為:" + buf);
}
}).start(); // 啟動零丁的線程來清空process.getInputStream()的緩沖區
InputStream isError = process.getErrorStream();
BufferedReader br2 = new BufferedReader(new InputStreamReader(isError));
StringBuilder buf = new StringBuilder();
String line = null;
while((line = br2.readLine()) != null){
buf.append(line + "\n");
}
System.out.println("毛病輸入成果為:" + buf);
try {
process.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
long endTime = System.nanoTime();
System.out.println("轉swf耗時: " + (endTime - beginTime) / 1000000000 + " 秒 " + sourceFile);
return new File(destFile);
}