Hello,
I have such Process request
try {
Process process = Runtime.getRuntime().exec("ping delfi.lt");
prinResults(process);
} catch (Exception e) {
e.printStackTrace();
}
in the printResults(process) I'm trying to write process to the file but without any success, the result.txt file stay empty
private static void prinResults(Process process) throws IOException {
// TODO
FileWriter fw = new FileWriter("result.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
int counter = 0;
while ((line = reader.readLine()) != null) {
counter++;
System.out.println("Line " + counter + " " + " " + line);
fw.write(line + "\n");
}
}
How correctly write to file process?