Reputation: 597
I am trying to write to a file, which another process can read. I am using the Printwiter to write to a file. But it doesnt write to the file as long as i dont terminate the program. I have eanbles the autflush on, and even explicitly flusing. The code is below -
import java.io.FileWriter;
import java.io.PrintWriter;
public class ReadFile {
public static void main(String[] args) {
try {
// Create a print writer
FileWriter fw = new FileWriter("D:\\SpringProjects\\RescilienceModel\\natural_resource.txt");
//BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(fw, true);
// Experiment with some methods
while(true)
{
pw.println(99);
pw.flush();
}
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
Upvotes: 0
Views: 958
Reputation: 7057
Two issues.
Check that while(true) loop, or it won't end.
close() your handle, or it won't release resources.
Upvotes: 3