Public voidCsv () {Try{string[] stringlist; String Sourcefilepath= "d:\\111\\ before sea itself. csv";//source FileFile File =NewFile (Sourcefilepath); InputStreamReader ISR=NewInputStreamReader (NewFileInputStream (file), "GBK"); String Destfilepath= "d:\\111\\ before sea itself ok.csv";//target file CsvreaderReader =NewCsvreader (ISR);//The default is comma delimiter, UTF-8 encoding Csvwriterwriter =NewCsvwrite (Destfilepath, ', ', Charset.forname ("GBK")); /** Readrecord () Determines if there is a record, getValues () reads the current record, and then the pointer moves down*/Reader.readrecord (); Writer.writerecord (Reader.getvalues ()); //To read a table header while(Reader.readrecord ()) {stringlist=reader.getvalues (); Writer.writerecord (stringlist); } reader.close (); Writer.close (); }Catch(Exception ex) {ex.printstacktrace (); } }
Use of csvreader,csvwriter and solve Chinese garbled characters