博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
读写CSV文件
阅读量:4213 次
发布时间:2019-05-26

本文共 943 字,大约阅读时间需要 3 分钟。

准备:需要引用javacsv.jar

CSV

   publicvoid readCsv()throws IOException {

       ArrayList<String[]> csvList = newArrayList<String[]>();

       String csvFilePath = sourcePath;

       CsvReader reader = newCsvReader(csvFilePath,',', Charset.forName("SJIS"));

       reader.readHeaders();

       while(reader.readRecord()) {

           csvList.add(reader.getValues());

       }

       reader.close();

       for (int row = 0;row < csvList.size(); row++) {

           String[] coldata=csvList.get(row);

           if(coldata!=null)

           {

               for(intcol=0;col<coldata.length;col++)

               {

                   System.out.println("ROW="+row+";COL="+col+";Data="+coldata[col]);

               }

           }

       }

   }

CSV

   publicvoidwriteCvs(ArrayList<String[]> dataList)throwsIOException {

       String csvFilePath = sumMetricsPath;

       CsvWriter wr = newCsvWriter(csvFilePath,',', Charset.forName("SJIS"));

       String[] header = { "Name","COL1","COL2","COL3","COL4","COL5" };

       wr.writeRecord(header);

       for(intindex=0;index<dataList.size();index++)

       {

           String[] data= dataList.get(index);

           wr.writeRecord(data);

       }

       wr.close();

   }



转载地址:http://kcumi.baihongyu.com/

你可能感兴趣的文章
POJ 1661 解题报告
查看>>
POJ 1101 解题报告
查看>>
ACM POJ catalogues[转载]
查看>>
ACM经历总结[转载]
查看>>
C/C++文件操作[转载]
查看>>
专业计划
查看>>
小米笔试:最大子数组乘积
查看>>
常见的排序算法
查看>>
5.PyTorch实现逻辑回归(二分类)
查看>>
6.PyTorch实现逻辑回归(多分类)
查看>>
8.Pytorch实现5层全连接结构的MNIST(手写数字识别)
查看>>
9.PyTorch实现MNIST(手写数字识别)(2卷积1全连接)
查看>>
hdu 3460 Ancient Printer(trie tree)
查看>>
中间数
查看>>
KMP求前缀函数(next数组)
查看>>
KMP
查看>>
poj 3863Business Center
查看>>
Android编译系统简要介绍和学习计划
查看>>
Android编译系统环境初始化过程分析
查看>>
user2eng 笔记
查看>>