CSV file read

Source: Internet
Author: User

 Public classGoods {PrivateString name; Private inttype; PrivateDouble Price;  PublicGoods () {} PublicGoods (String name,inttype, Double price) {        Super();  This. Name =name;  This. Type =type;  This. Price =Price ; }     PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }     Public intGetType () {returntype; }     Public voidSetType (inttype) {         This. Type =type; }     PublicDouble GetPrice () {returnPrice ; }     Public voidSetprice (Double price) { This. Price =Price ; }    }

 Public classDemo { Public Static voidFun () {String path= "Csv/4399.csv"; List<goods>list =NewArraylist<goods>(); Try{Csvreader Reader=NewCsvreader (path, ' \ t '), Charset.forname ("Utf-16le")); Reader.readheaders ();//Skip the header if you need a table header, don't write this sentence. reader.readheaders ();            Reader.readheaders (); intName_pos = 0; //Product name Location intType_pos = 1; //Product type location intPrice_pos = 2; //Commodity price location  while(Reader.readrecord ()) { //row-by-line reading of data except header Goods Goods=NewGoods ();                Goods.setname (Reader.get (Name_pos));                Goods.settype (Integer.parseint (Reader.get (Type_pos)));                Goods.setprice (Double.parsedouble (Reader.get (Price_pos)));            List.add (goods);        } reader.close (); } Catch(IOException e) {e.printstacktrace (); }                 for(Goods goods:list) {System.out.println (Goods.getname ());            System.out.println (Goods.gettype ());        System.out.println (Goods.getprice ()); }    }     Public Static voidMain (string[] args) {fun (); }}

CSV file read

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.