Summary of Opencsv Usage

Source: Internet
Author: User

Recently, there was a requirement in the work to export CSV format files, before encountering similar requirements, finally found on Google Opencsv, and provide Java API

Opencsv Address: https://code.google.com/p/opencsv/

The site provides a complete sample code, here only a CSV read and write sample code, others, please move to the official website to see.

Import Java.util.Arrays; public class Csvafter {//define format of CSV file one time and use everywhere//human READABL
                        E configuration private static final CSV CSV = CSV. Separator (';') . quote (' \ '). Skiplines (1). CharSet ("UTF-8"). C

        Reate (); Don't throw checked exceptions public static void main (string[] args) {String fileName = ' tes
                
                T.csv ";
                        Csvwriter'll be closed after the end of processing csv.write (FileName, New Csvwriteproc () {
                                public void process (Csvwriter out) {out.writenext ("Header1", "Header2");
                                Out.writenext ("V11", "V12");
                        Out.writenext ("V21", "v22");
                
    }
                });            Csvreader'll be closed after the end of processing//less code to process CSV content->  Less bugs Csv.read (fileName, New Csvreadproc () {public void procrow (int rowIndex,    
                        String ... values) {System.out.println (RowIndex + "#" + arrays.aslist (values));
        }
                }); }
}






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: info-contact@alibabacloud.com 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.