【发布时间】:2020-05-22 22:42:39
【问题描述】:
我需要按第三列对 csv 文件进行排序,但我卡住了,找不到解决方案。
代码:
import java.util.*;
import java.io.*;
public class SalesStatistics{
public static void main(String[] args){
String filePath = "Filepath";
ArrayList<String> csvValues = new ArrayList<String>();
try{
BufferedReader br = new BufferedReader( new FileReader(filePath));
String strLine = "";
StringTokenizer str = null;
while( (strLine = br.readLine()) != null){
str = new StringTokenizer(strLine, ",");
while(str.hasMoreTokens())
csvValues.add(str.nextToken());
}
}catch(Exception e){
System.out.println("Exception while reading csv file: " + e);
}
}
}
我的 csv 文件是这样的:
1001,Name1,9
1005,Name2,20
1007,Name3,14
我需要它是:
1001,Name1,9
1007,Name3,14
1005,Name2,20
【问题讨论】: