我有一个名为“integers.csv”的文件,其中有2000万个数据(类型:长)。我创建此函数将它们存储到Record类(只有一个长变量)。它有效,但速度很慢,因为它每秒存储大约1k个数字。有没有办法快速存储?
private static void loadArray(String filepath, Sorting<Record> orderedArray) throws IOException, SortingException{
System.out.println("\nLoading data from file...\n");
Path inputFilePath = Paths.get(filepath);
try(BufferedReader fileInputReader = Files.newBufferedReader(inputFilePath, ENCODING)){
String line = null;
while((line = fileInputReader.readLine()) != null){
String[] lineElements = line.split("\n");
Record record1 = new Record(Long.parseLong(lineElements[0]));
orderedArray.add(record1);
}
}
System.out.println("\nData loaded\n");
}