• Post Reply Bookmark Topic Watch Topic
  • New Topic

PrintWriter: File is getting terminated prematurely without any errors

 
Nikhil Menon
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

new PrintWriter(new OutputStreamWriter(new FileOutputStream("filename")))

I am using a printWriter as given above to write large amounts of data. There is also a considerable (sometime 15 mins) wait for loading data from database that needs to be written to the file.
The problem is that the file is getting terminated prematurely. I checked all the log file, there are no signs of any error.

Is it possible that the Socket got closed unexpectedly? Or is there any timeout for which Outstream can be kept open? Please advice.

Has anyone experienced this issue?
 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nikhil,

Probably by posting the important snippets of your code may be helpful for anyone to look into the problem. Without that, I believe its extremely difficult to pin point the issue.
 
Nikhil Menon
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ravi


The problem is that, the file to which the PrintWriter printed the data contains only a portion of the data. However, the program completes successfully, there are no errors.

Please let me know if this information is sufficient. I appreciate any pointers that you think might contribute to this issue.
[ August 07, 2008: Message edited by: Nikhil Menon ]
 
Prashant Sehgal
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try calling pw.flush() before pw.close()
 
Nikhil Menon
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying that now along with autoflush, but the current code (just calling close() and not flush()) works most of the times. Occasionally I am facing data loss that was in the buffer. Do you think it is due to any socket timeout? Or is it due to buffer size? any suggestions?
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nikhil Menon:
Do you think it is due to any socket timeout? Or is it due to buffer size?


If that were the case, you'd get an exception. Are you handling exceptions correctly?
 
Nikhil Menon
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the exceptions, if any, are handled properly. I did not receive any exception in this case.
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to isolate the problem and post real code. We just don't have a good enough picture of your problem to give you any help.
 
Nikhil Menon
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue got resolved, we were able to identify there Object holding the PrintWriter instance was not thread safe and multiple threads were using the object and changing the PrintWriter instance to point to a new instance!!!

Thank you everyone for taking time in looking into the question.
[ August 25, 2008: Message edited by: Nikhil Menon ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!