Reputation: 7
I have been trying to get data to be written from command prompt to a JTextArea, but it doesn't want to work for me, so I tried writing the data to a text file. SO far it writes one line then stops, so I need to continuously read from the text file until I stop it. Here is my code: `
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) {`
Thank you for your help, I have been scouring my brain and the internet for hours with no luck :/
Upvotes: 0
Views: 947
Reputation: 326
BufferedReader in = new BufferedReader(new FileReader(fileName))
String line2;
while ((line2 = in.readLine()) != null) {
//do something
}
Upvotes: 2