什么是在java中扫描非常大的文件的最快方法? [英] what's the fastest way to scan a very large file in java?

查看:400
本文介绍了什么是在java中扫描非常大的文件的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我有一个非常大的文本文件。
性能真的很重要。

Imagine I have a very large text file. Performance really matters.

我想做的就是扫描它以寻找某个字符串。
也许我想算一下我有多少,但这真的不是重点。

All I want to do is to scan it to look for a certain string. Maybe I want to count how many I have of those, but it really is not the point.

重点是:最快的方法是什么?

The point is: what's the fastest way ?

我不关心它需要快速维护。

I don't care about maintainance it needs to be fast.

快速是关键。

推荐答案

对于一次性搜索使用扫描仪,如建议这里

For a one off search use a Scanner, as suggested here


一个简单的技术可能比使用Scanner的
快得多
,使用方法
findWithinHorizo​​n()。如果您使用带有File对象的
构造函数,
Scanner将在内部生成
FileChannel来读取该文件。对于
模式匹配,最终将使用
Boyer-Moore算法进行有效的
字符串搜索。

A simple technique that could well be considerably faster than indexOf() is to use a Scanner, with the method findWithinHorizon(). If you use a constructor that takes a File object, Scanner will internally make a FileChannel to read the file. And for pattern matching it will end up using a Boyer-Moore algorithm for efficient string searching.

这篇关于什么是在java中扫描非常大的文件的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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