Java BufferedReader回到文本文件的顶部? [英] Java BufferedReader back to the top of a text file?

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

问题描述

我目前在相同的文本文件上初始化了2个 BufferedReader 。当我使用第一个 BufferedReader 阅读文本文件时,我使用第二个从顶部再次传递文件。

I currently have 2 BufferedReaders initialized on the same text file. When I'm done reading the text file with the first BufferedReader, I use the second one to make another pass through the file from the top. Multiple passes through the same file are necessary.

我知道 reset(),但需要在之前调用 mark() mark()需要知道文件的大小,我不认为我应该打扰。

I know about reset(), but it needs to be preceded with calling mark() and mark() needs to know the size of the file, something I don't think I should have to bother with.

想法?包?库?代码?

感谢
TJ

Thanks TJ

推荐答案

刚刚创建一个新的 BufferedReader 从顶部读取的缺点?我希望操作系统缓存文件,如果它足够小。

What's the disadvantage of just creating a new BufferedReader to read from the top? I'd expect the operating system to cache the file if it's small enough.

如果您关心性能,是否证明它是瓶颈?我只是做最简单的事情,不要担心,直到你有一个具体的理由。我的意思是,你可以将整个事情记录在记忆中,然后对结果进行两次传递,但是再次重新开始,新的阅读器将再复杂一些。

If you're concerned about performance, have you proved it to be a bottleneck? I'd just do the simplest thing and not worry about it until you have a specific reason to. I mean, you could just read the whole thing into memory and then do the two passes on the result, but again that's going to be more complicated than just reading from the start again with a new reader.

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

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