Java file cursor

Is there any library for using some kind of cursor over a file? I have to read large files, but I can not afford to read them all at once in memory. I know java.nio, but I want to use a higher level API.

A little backgrond: I have a tool written in GWT that parses the submitted XML documents and then pretty xml prints, by the way. I am currently writing pretty printed xml for a temporary file (my lib will throw me an OOMException if I use simple strings), but the temp file size is close to 18 megabytes, I cannot allow the RPC GWT to be answered using 18 megs :)

So, I have a widget to show only the xml part (check this example ), but I need to read the corresponding part of the file.

+2
source share
3 answers

Have you looked at using FileChannels (i.e. memory mapped files)? Memory mapped files allow you to manipulate large files without transferring the entire file to memory.

Here's a link to a good introduction: http://www.developer.com/java/other/article.php/1548681

+4
source

Maybe java.io.RandomAccessFile might come in handy. See: http://java.sun.com/j2se/1.4.2/docs/api/java/io/RandomAccessFile.html

+2
source

I do not understand when you request a "higher level API" when positioning the file pointer. These are the higher levels that may be required to control the cursor. If you want to control, go lower, not higher.

I am sure that the lower levels of Java io clases allow you to place yourself anywhere in any size without reading anything in memory until you want to. I know I did it before. Try RandomAccessFile as an example.

0
source

All Articles