Android 为什么导入CSV需要这么长时间?我如何加快导入速度?

Android 为什么导入CSV需要这么长时间?我如何加快导入速度?,android,csv,Android,Csv,我有一个相当大的CSV文件(约.5Mb,16000行,6列),我目前正在将其作为Android应用程序的一部分导入阵列中。我将CSV存储在assets文件夹中,并在每次使用时重新导入它。导入现在需要7或8秒(每行大约47毫秒) 以下是我在CSV中读取的代码: @Override protected ArrayList<Car> doInBackground(Void... voids) { ArrayList<Car&

我有一个相当大的CSV文件(约.5Mb,16000行,6列),我目前正在将其作为Android应用程序的一部分导入阵列中。我将CSV存储在assets文件夹中,并在每次使用时重新导入它。导入现在需要7或8秒(每行大约47毫秒)

以下是我在CSV中读取的代码:

         @Override
         protected ArrayList<Car> doInBackground(Void... voids) {
            ArrayList<Car> toReturn = new ArrayList<Car>(); 

            try {

                BufferedReader CSVFile = new BufferedReader(new InputStreamReader(CarChooser.this.getAssets().open(CSV_NAME)));
                String dataRow = CSVFile.readLine();
                Car car;
                while (dataRow != null){
                    // split on the comma only if that comma has zero, or an even number of quotes in ahead of it
                    String[] dataArray = dataRow.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
                    if(dataArray.length != 6) throw new IllegalStateException("Row length should be 6. Row length = " + dataArray.length);

                    int year = Integer.parseInt(dataArray[0]);
                    String make = Utils.removeQuotes(dataArray[1]);
                    String model = Utils.removeQuotes(dataArray[2]);
                    float mpgCty = Float.parseFloat(dataArray[3]);
                    float mpgHwy = Float.parseFloat(dataArray[4]);
                    float mpgCmb = Float.parseFloat(dataArray[5]);

                    car = new Car(year, make, model, mpgCty, mpgHwy, mpgCmb);

                    toReturn.add(car);

                    dataRow = CSVFile.readLine(); 
                }
                CSVFile.close();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return toReturn;
         }
@覆盖
受保护的ArrayList doInBackground(无效…无效){
ArrayList toReturn=新的ArrayList();
试一试{
BufferedReader CSVFile=新的BufferedReader(新的InputStreamReader(CarChooser.this.getAssets().open(CSV_NAME));
字符串dataRow=CSVFile.readLine();
汽车;
while(dataRow!=null){
//仅当逗号前面有零个引号或偶数个引号时,才拆分该逗号
字符串[]dataArray=dataRow.split(“,(?=([^\“]*\”[^\“]*\”[^\“]*\”*[^\“]*$”)”);
如果(dataArray.length!=6)抛出新的IllegalStateException(“行长度应为6.Row length=“+dataArray.length”);
int year=Integer.parseInt(数据数组[0]);
字符串make=Utils.removeQuotes(dataArray[1]);
字符串模型=Utils.removeQuotes(dataArray[2]);
float-mpgCty=float.parseFloat(数据数组[3]);
float-mpgHwy=float.parseFloat(数据数组[4]);
float-mpgCmb=float.parseFloat(dataArray[5]);
car=新车(年份、品牌、型号、mpgCty、mpgHwy、mpgCmb);
t返回。添加(汽车);
dataRow=CSVFile.readLine();
}
CSVFile.close();
}捕获(非法状态){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
回归回归;
}
以下是我的问题:

  • 这是我应该期待的时间吗

  • 如果没有,为什么要花这么长时间

  • 加快整个过程的最佳方式是什么


  • 我没有使用SQL数据库的经验,但这听起来像是我应该研究的问题。

    如果不知道您对这些数据做了什么,很难给出任何建议。您对该列表做了什么?该列表用于填充3个相关微调器,您可以在其中选择汽车年份,然后是品牌,然后是车型。我不是确定你的问题是什么,但我愿意成为一个SQLite DB会更快。然后我会发出三个查询来填充你的微调器,并在此基础上找到你的车。我可以在回答中给出更多细节,但我没有确切的数字说它会更快。