exception while Read very large file > 300 MB
Hi I want to read a file which has size of more than 300 MB.
While i m executing my code, i m getting
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Below is my code
1. FileChannel fc = new FileInputStream(fFile).getChannel();
2.CharBuffer chrBuff = Charset.forName("8859_1").newDecoder().decode(fc.m ap(FileChannel.MapMode.READ_ONLY, 0, fc.size()));
3.fc.close();
Im getting the exception in the line 2.
Even though i increased the Heap space up to 900 Mb, i m getting this error.
(FYI)
I executed in command prompt like below,
java -Xms128m -Xmx1024m readLargeFile
Kindly give a solution for this. is there any other best way to read large text file ??
I m waiting for your reply..
Thanks in advance
Re: exception while Read very large file > 300 MB
Hello ps.ganesh. Welcome to the Java Programming Forums.
In future, please do not double post the same thread.
Please take a look at this similar thread:
http://www.javaprogrammingforums.com...eap-space.html
Have you tried this method of reading the file?
http://www.javaprogrammingforums.com...redreader.html
Re: exception while Read very large file > 300 MB
Thanks for your reply.
My task is to open a large file in READ&WRITE mode and i need to search some portion of text in that file by searching starting and end point.
Then i need to write that searched area of text to a new file and delete that portion from the original file.
The above process i will do more times.
So I thought that for these process, it will be easy by loading the file into memory by CharBuffer and can search easily by MATCHER class.
Above is my task, then now suggest me some efficient ways.
Note that my file size will be more and using JAVA only i've to do these things.
Thanks in Advance...