Special Note: I blog part of the reference network other blogs, but I have personally written and verified through. If you find that the blog has errors, please prompt to avoid misleading other people, thank you! Welcome reprint, but remember to indicate the source of the article: http://www.cnblogs.com/mao2080/
1 Public classCsvutils {2 3 /**4 * 5 * Description: Export6 * @author[email protected]7 * @created August 26, 2017 pm 2:39:138 * @since 9 * @paramFile csv (path + file name), CSV file does not exist automatically createdTen * @paramdataList data (data1,data2,data3 ... ) One * @return A */ - Public Static BooleanExportcsv (file file, list<string>dataList) { -FileOutputStream out=NULL; theOutputStreamWriter OSW =NULL; -BufferedWriter bfw=NULL; - Try { -out =Newfileoutputstream (file); +OSW =NewOutputStreamWriter (out, "GBK"); -BFW =NewBufferedWriter (OSW); + if(DataList! =NULL&&!Datalist.isempty ()) { A for(String data:datalist) { atBfw.append (data). Append ("\ r")); - } - } - return true; -}Catch(Exception e) { - return false; in}finally{ - ioutil.closequietly (BFW, OSW, out); to } + } - the /** * * $ * Description: ImportPanax Notoginseng * @author[email protected] - * @created August 26, 2017 pm 2:42:08 the * @since + * @paramFile csv (path + file name) A * @return the */ + Public StaticList<string>importcsv (file file) { -List<string> dataList =NewArraylist<string>(); $BufferedReader br =NULL; $ Try { -BR =NewBufferedReader (Newfilereader (file)); -String line = ""; the while(line = Br.readline ())! =NULL) { - Datalist.add (line);Wuyi } the}Catch(Exception e) { - Wu}finally{ - ioutil.closequietly (BR); About } $ returndataList; - } -}
Reference website
Http://www.cnblogs.com/linjiqin/p/3535067.html
"Go" Java Operation CSV file import and Export