我一直在尝试将数据从命令提示符写入 JTextArea,但它不想为我工作,所以我尝试将数据写入文本文件。到目前为止它写了一行然后停止,所以我需要不断地从文本文件中读取,直到我停止它。这是我的代码:`
try {
File consoleLog = new File("tempConsole.txt");
Process p = Runtime.getRuntime().exec("cmd /c minecraft.lnk");
//writes the text from the console to tempConsole.txt
BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream()));
BufferedWriter consoleOutputWriter = new BufferedWriter(new FileWriter("tempConsole.txt"));
consoleOutputWriter.write("" + input);
consoleOutputWriter.newLine();
//reads the tempConsole.txt
BufferedReader consoleOutputReader = new BufferedReader (new FileReader("tempConsole.txt"));
//writes the tempConsole.txt to the on-sceen JTextArea.
String outputFromTemp = consoleOutputReader.readLine();
console.setText(outputFromTemp);
consoleOutputWriter.close();
} catch (Exception ex) {`
感谢您的帮助,我一直在搜索我的大脑和互联网几个小时,但没有运气:/