java - Java - 实际上读取大型格式文件并存储它的最快方法是什么
问题描述
什么是禁食方法:
读取文件,(缓冲阅读器??)
快速转换(例如:字符串到 int)
最快的存储方式(ArrayList,HashMap?)
从一个大文件
[文件:]
格式:字母 hashcode-int double int int boolean
U 1 234.003 30 40 50 true
T 2 234.003 10 60 40 false
Z 3 17234.003 30 40 50 true
M 4 0.500 30 40 50 true
...
/* 1000000+ lines */
[读者]
public static DataBase filereader() {
InputStream S = new BufferedInputStream(new FileInputStream(filename)
Scanner FS = new Scanner(S);
DataBase DB = new DataBase;
while (FS.hasNextLine() == true) {
String A = FS.next();
int hash = FS.nextInt();
double B = FS.nextDouble();
int C = FS.nextInt();
int D = FS.nextInt();
boolean E = FS.nextBoolean();
// hash is hashcode for all values A B C D E in DataBase DB
DB.listA.put(hash,A);
DB.listB.put(hash,B);
DB.listC.put(hash,C);
DB.listD.put(hash,D);
DB.listE.put(hash,E);
}
}
[数据库]
public class DataBase () {
public HashMap<Integer,String> listA;
public HashMap<Integer,Double> listB;
public HashMap<Integer,Integer> listC;
public HashMap<Integer,Integer> listD;
public HashMap<Integer,Boolean> listE;
/* ... */
}
解决方案
推荐阅读
- r - 在 Drake 工作流程 R 中清理内存
- vue.js - Bootstrap-vue b-dropdown ul 菜单设置为隐藏不显示无
- html - 如何将 Bootstrap 样式与多个 html 文件匹配?
- python - 用户名唯一性 cs50 财务
- django - 尽管使用了模板,但 AsserrtTemplateUsed 失败...?
- angular - 电子 IPC 消息
- go - Golang gRPC 客户端连接到 GKE
- python - 将日期对象从 python 插入到 mysql
- javascript - Show custom text in number input
- c# - Xamarin 表单分组列表视图不显示迭代行