File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Read from file without loading into the JVM? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Read from file without loading into the JVM?" Watch "Read from file without loading into the JVM?" New topic
Author

Read from file without loading into the JVM?

Derek White
Greenhorn

Joined: Jul 24, 2008
Posts: 14
Is it possible to read/write (using a stream maybe?) from a file without actually loading the whole thing into the JVM?

I am used to loading the whole file into memory but I realize if a file becomes to large it will hog resources. Is there any way I can maintain low memory usage and the ability to constantly read/write data?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18140
    
    8

Of course. Simply read part of the file, process it, then throw it away and read the next part of the file.

A common example of this is where you read a text file one line at a time and process each line separately.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

By default, FileInputStream and FileReader don't store more than a few kilobytes. Just keep on calling on of the read methods (or readLine() if you've wrapped them in a BufferedReader) and process the bytes / chars / lines directly instead of storing them.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read from file without loading into the JVM?
 
Similar Threads
Update file content without rewrite the whole file issue
Read/Write
How get full Stream of document into other InputStream?
Accessing hashmaps directly from disk instead of memory
Adding attributes to root tag