Java文件游标 [英] Java File Cursor

查看:147
本文介绍了Java文件游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一些库在文件上使用某种光标?我必须阅读大文件,但不能一次全部读入内存。我知道java.nio,但我想使用更高级别的API。

有一点小小的提示:我有一个用GWT编写的工具,用于分析提交的xml文档然后漂亮的打印xml等。目前我正在写一个漂亮的打印XML到一个临时文件(如果我使用普通的字符串,我的lib会给我一个OOMException),但临时文件的大小接近18兆,我不能回应一个GWT RPC 18所以我可以有一个小部件来显示只有一部分的XML(检查这个 example ),但我需要读取文件的相应部分。 / div>

你有没有看过使用FileChannels(即内存映射文件)?内存映射文件允许你操作大文件,而不需要把整个文件放到内存中。

这里有一个很好的介绍:
http://www.developer.com/java/other/article.php/1548681


Is there some library for using some sort of cursor over a file? I have to read big files, but can't afford to read them all at once into memory. I'm aware of java.nio, but I want to use a higher level API.

A little backgrond: I have a tool written in GWT that analyzes submitted xml documents and then pretty prints the xml, among other things. Currently I'm writing the pretty printed xml to a temp file (my lib would throw me an OOMException if I use plain Strings), but the temp file's size are approaching 18 megs, I can't afford to respond a GWT RPC with 18 megs :)

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

解决方案

Have you taken a look at using FileChannels (i.e., memory mapped files)? Memory mapped files allow you to manipulate large files without bringing the entire file into memory.

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

这篇关于Java文件游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆