用Java快速读取大数据文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19466834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reading large data files quickly in Java
提问by Eduardo
I have a large .txt file with data in lines in the format
我有一个大的 .txt 文件,其中包含格式为行的数据
String int int double int int int double
String int int double int int int double
eg:
例如:
monday 1 -1 43.5 2 1 1 -99999
tuesday 3 12 43.02 4 11 12 5.2
星期一 1 -1 43.5 2 1 1 -99999
星期二 3 12 43.02 4 11 12 5.2
My text file has approximately 20,000 lines so i need a quick method of reading this in java.
我的文本文件大约有 20,000 行,所以我需要一种在 Java 中快速阅读的方法。
What is the quickest method to read this kind of file in?
读取此类文件的最快方法是什么?
EDIT: I have used a function named textscan in MATLAB which worked perfectly (however i want to use java) so a similarly fast method would be perfect
编辑:我在 MATLAB 中使用了一个名为 textscan 的函数,它运行良好(但是我想使用 java),因此类似的快速方法将是完美的
采纳答案by Vibhu
String scan;
FileReader file = new FileReader("C:\Users\workspace\learn\scan.txt");
BufferedReader br = new BufferedReader(file);
while((scan = br.readLine()) != null)
{
System.out.println(scan);
}
br.close();