• Post Reply Bookmark Topic Watch Topic
  • New Topic

Write file even program terminated

 
Arvind Subramanian
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while writing the large file if i terminated the program manually in between means file was only empty.. The data already written was not present. I need to save (like) the content every time i write ... is it possible ??



PrintWriter out=null;
try {
out = new PrintWriter(new FileWriter("result.txt"));
for(long i=10000; i<10006; i++ ){
System.out.print(i+"~");
out.write(i+"~");
if(i%100==0)
obj.getLo(i+"");
validResponse=obj.get(""); // modified for space.
if(validResponse!=null){
out.write(validResponse.toString());
}
Thread.sleep(1000);
}
out.close();
} catch (Exception e) {
System.out.println(""+e.getMessage());
e.printStackTrace();
}
finally{
if(out!=null)
out.close();

}
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling out.flush after each write may work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!