Can I write to the end of a 5GB file in Java? This question came up in my office and no one is sure what the answer is.
Using BufferedReader and Java Streams To do that, we will use BufferedReader, which provides a Stream of strings read from the file. Next is an example of using Java Stream provided by BufferedReader to process a very very large file (10GB). Now, we will test the method that uses BufferedReader to read a 10GB file.
Write text files faster with BufferedWriter BufferedWriter adds another 8 KB buffer for characters, which are then encoded in one go when the buffer is written (instead of character by character). This second buffer reduces the writing time for 100,000,000 characters to approximately 370 ms.
This should be possible fairly easily using a RandomAccessFile. Something like the following should work:
String filename;
RandomAccessFile myFile = new RandomAccessFile(filename, "rw");
// Set write pointer to the end of the file
myFile.seek(myFile.length());
// Write to end of file here
Yes. Take a look at this link RandomAccessFile
http://java.sun.com/javase/6/docs/api/java/io/RandomAccessFile.html#seek(long)
That is , you open the file, and then set the position to the end of the file. And start writing from there.
Tell us how it went.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With