• Post Reply Bookmark Topic Watch Topic
  • New Topic

PrintWriter can only write 130k?  RSS feed

 
Zhixiong Pan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

I want to write a large file, and planned to use PrintWriter.During the experiments, I found such class can only write 130k, how I can write more contents to a file?Thank you.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you provide a reference for this limitiation?
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just create a file of length 3316890 bytes using
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such limitation.

How did you find this out? Did you get an error message when you tried to write more than 130 KB of data? If yes, then what was the error message?
 
Zhixiong Pan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

My code :

The templet.rtf has 640 lines and dest.rtf only have 580 lines. No error has be thrown.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have not closed 'out'.
You are swallowing exceptions so you can't tell if anything is wrong.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not flushing or closing the output stream when you're done. Because of that, some of the data may have not been written to the output file when the program ends.

Make sure you call out.flush() and out.close() at the end of the program.

Also close the input stream by calling in.close().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!