1
我想要得到我的系統正在運行的進程(即任務管理器)並將它們保存在一個文件中,但問題是我正在運行進程但它們沒有寫入文件 我的代碼是運行時進程到java中的文件
BufferedWriter out = new BufferedWriter(new FileWriter("C:\\Users\\Zeeshan Nisar\\Desktop\\process.txt", true));
// Get process and make reader from that process
Process p = Runtime.getRuntime().exec("tasklist.exe");
BufferedReader s = new BufferedReader(new InputStreamReader(p.getInputStream()));
// While reading, print.
String input = null;
while ((input = s.readLine()) != null) {
out.write(input);
out.newLine();
}
out.close();
如果您只是寫入System.out,會得到什麼輸出結果? –
圖像名稱PID會話名稱會話編號使用 系統空閒進程0服務0 24 K 系統4服務0 304 K @ScaryWombat –
看不到此代碼的任何問題。任何未報告的錯誤? –