首页 > 解决方案 > 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;

/* ... */

}





标签: javahashmapstorelarge-files

解决方案


推荐阅读