从CSV文件中读取,解析和排序数据

时间:2013-07-31 12:31:17

标签: java csv

我需要读取一个csv文件,解析它然后根据这些参数对值进行排序:

  1. 十大畅销产品
  2. 表现最佳的分支机构
  3. 表现最差的分支
  4. 销售额最高的员工
  5. 到目前为止,这是我的代码,有关如何对其进行排序的任何建议吗?

    import java.io.*;
    
    public class CSV {
    public static void main(String[] args) throws IOException {
        try (BufferedReader CSVFile = new BufferedReader(new FileReader("/K:/ConnexicaWork/data/data.csv"))) {
            String[] dataArray = null;
            String data = CSVFile.readLine(); // Read first line.
    
            while (data != null) {
                data = data.replace(",00", ".00");
                dataArray = data.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)"); //split on the comma only if that comma has zero, or an even number of quotes in ahead of it.
                for (String item : dataArray) {
                    System.out.print(dataArray[34] + " # ");
                }
                System.out.println(); // Print the data line.
                data = CSVFile.readLine(); // Read next line of data.
            }
        }
    
    
        System.out.println();  // End the printout with a blank line.
    
    }
    }
    

0 个答案:

没有答案