| | |
Reading Large Files
![]() |
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
I am trying to to read and write large files about 600M.
The thing is when i use the normal FileOutputStream methods an exception gets thrown saying
This is how i am trying to read the file
My computer does have sufficient memory
I tried adding this in the while loop but it does not work and i got the same exception thrown by the JVM again
My question is basically how do i increase the memory programatically
or is there away in which i can read the file without having the above exception thrown by the JVM?
Any help i greatly appreciated
Thank You
Yours Sincerely
Richard West
I am trying to to read and write large files about 600M.
The thing is when i use the normal FileOutputStream methods an exception gets thrown saying
Java Syntax (Toggle Plain Text)
java.lang.OutofMemory
This is how i am trying to read the file
Java Syntax (Toggle Plain Text)
FileOutputStream out = new FileOutputStream("C:/my_life_story.zip"); InputStream in = //an input stream from a socket, etc int len = 0; byte[] buffer1 = new byte[1024]; while ((len = in.read(buffer1)) > 0) { out.write(buffer1, 0, len); } in.close(); out.close();
My computer does have sufficient memory
I tried adding this in the while loop but it does not work and i got the same exception thrown by the JVM again
Java Syntax (Toggle Plain Text)
System.gc();
My question is basically how do i increase the memory programatically
or is there away in which i can read the file without having the above exception thrown by the JVM?
Any help i greatly appreciated
Thank You
Yours Sincerely
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Try flushing the buffer after every write.
The only thing I can think of that's eating up memory here is the outputbuffer. It may not be flushing automatically, causing the JVM to attempt to map the entire output into RAM instead of writing it directly to disk (which you seem to be attempting to do).
The only thing I can think of that's eating up memory here is the outputbuffer. It may not be flushing automatically, causing the JVM to attempt to map the entire output into RAM instead of writing it directly to disk (which you seem to be attempting to do).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: May 2005
Posts: 55
Reputation:
Solved Threads: 1
Maybe you should try setting the maximum heap size for the JVM.
You can put higher values if needed.
For more help, www.NeedProgrammingHelp.com
Java Syntax (Toggle Plain Text)
java -Xmx256m MyClass
For more help, www.NeedProgrammingHelp.com
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
Is this what you meant NPH
Unfortunately i can't use the above code because the thing is the application is in a jar file on windows platform and users that use this application to run it usually double click on the jar file to run it. Is there a way to do what you suggested programatically maybe by the use of properties?
I think maybe jwenting maybe right that i have to flush and i will be trying it out.
On another question do any of you guys know how to increase the heap size programatically?
Richard West
Is this what you meant NPH
Java Syntax (Toggle Plain Text)
java -Xmx650m MyProgram
Unfortunately i can't use the above code because the thing is the application is in a jar file on windows platform and users that use this application to run it usually double click on the jar file to run it. Is there a way to do what you suggested programatically maybe by the use of properties?
I think maybe jwenting maybe right that i have to flush and i will be trying it out.
On another question do any of you guys know how to increase the heap size programatically?
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
![]() |
Similar Threads
- Reading Binary Files in VB (Visual Basic 4 / 5 / 6)
- Trying to send large files overseas securely (Networking Hardware Configuration)
- downloading very large files with PHP (PHP)
- problems with reading video files (Windows NT / 2000 / XP)
- PHP for large files (PHP)
- how to open large files not supported by aol (Windows 95 / 98 / Me)
- Problem Downloading large files (ASP)
Other Threads in the Java Forum
- Previous Thread: do while loop - not stopping!!
- Next Thread: Can Anyone Help Me Please?
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card character class client code collision component crashcourse css csv database eclipse ee error fractal free ftp game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting researchinmotion rotatetext scanner se server service set sms software sort sql string swing test textfield threads tree trolltech ubuntu utility windows







