Results 1 to 4 of 4
- 12-30-2008, 04:03 PM #1
Member
- Join Date
- May 2008
- Posts
- 69
- Rep Power
- 0
Problem while writing to file, size greater than 15MB ..?
Dear Members,
FileReader reader = new FileReader("c:/sample.sql");
BufferedReader buffer = new BufferedReader(reader);
String readLine = null;
StringBuffer line = new StringBuffer();
while ((readLine = buffer.readLine()) != null)
{
line.append(readLine + "\n");
}
In the above code "sample.sql" file size is around 15MB so it throws an "java.outof Memory exception" Java Heap space error...
Please help me how to write a large file to a file using java.
Also i need the full data from the file, i need all the data of size 15MB to write to a file.
Regards,
Prabhu.
- 12-30-2008, 05:13 PM #2
Sounds like you want to read the contents of one file and then write it to another file. If that is the case, don't read the entire file into memory and then write it back out. Read a block (line or whatever) and then write it. Get rid of the StringBuffer.
- 12-30-2008, 05:20 PM #3
Member
- Join Date
- May 2008
- Posts
- 69
- Rep Power
- 0
Problem while writing to file, using string buffer
@Steve
Hi steve it sounds great, however is it ok to do by setting the StringBuffer length, by using StringBuffer.setLength(File.length());
Please let me know if it is bad idea.
How to read a file upto a certain block and write to a file and then the remaining.
Please do you have any sample code for this it would be better.
Also my file size would be greater than 1GB or 2GB.
Regards,
Prabhu.
- 12-30-2008, 05:28 PM #4
Member
- Join Date
- May 2008
- Posts
- 69
- Rep Power
- 0
Hi Steve,
Sorry my idea will not be better as im getting the data as an InputStream, also i would not be knowing the file size at the beginning.
Also i forgot to let you know:
Im getting the input data to file as an InputStream, then by using bufferedReader im reading it and appending it to a stringbuffer.
Similar Threads
-
Problem while writing xml file
By Rajesh Sahu in forum Java ServletReplies: 0Last Post: 12-23-2008, 04:53 PM -
How can you get the exact size of a file in bytes.
By J-Live in forum New To JavaReplies: 7Last Post: 10-28-2008, 01:41 PM -
swapping the contents of the file and writing to another file
By Ms.Ranjan in forum New To JavaReplies: 9Last Post: 07-10-2008, 04:52 PM -
Transaction has timed out due to no client activity for greater than {1} seconds
By Sayed in forum Advanced JavaReplies: 1Last Post: 06-30-2008, 07:14 AM -
File size
By eva in forum New To JavaReplies: 2Last Post: 12-19-2007, 09:27 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks