Java read import CSV format file

Source: Internet
Author: User

Tag: coded head close resolves ACS har write DMI Import

First, be prepared to download a Javacsv.jar rack package

public void Readecsv () {
try {

           ArrayList<String[]> csvList = new ArrayList<String[]>(); //用来保存数据  //注明:或者可以通过前端上传的文件,用一个方法获取上传文件名uploadName(String)    String csvFilePath = "C:\\Users\\Administrator\\Desktop/05122017.csv";       CsvReader reader = new CsvReader(csvFilePath,‘,‘,Charset.forName("GBK"));    //解决中文编码             reader.readHeaders(); // 跳过表头   如果需要表头的话,不要写这句。              while(reader.readRecord()){ //逐行读入除表头的数据               csvList.add(reader.getValues());       }                   reader.close();           for(int row=0;row<csvList.size();row++){  

String cell = csvlist.get (row) [0]; You can specify the fetch content by obtaining the data in column No. 0 of Row row


                 System.out.println("姓名:"+cell)                       }                }catch(Exception ex){      System.out.println(ex);  }  



    • Writing to a CSV file

public void Writecsv () {
try {

          String csvFilePath = "E:\\xb:/05122017.csv";       CsvWriter wr =new CsvWriter(csvFilePath,‘,‘,Charset.forName("SJIS"));       String[] contents = {"aaaaa","bbbbb","cccccc","ddddddddd"};                           wr.writeRecord(contents);       wr.close();   } catch (IOException e) {      e.printStackTrace();   


Java read import CSV format file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.