public void Csv(){ try { String[] stringList; String sourceFilePath = "D:\\111\\前海自身.csv"; //源文件 File file =new File(sourceFilePath); InputStreamReader isr=new InputStreamReader(new FileInputStream(file),"GBK"); String destFilePath= "D:\\111\\前海自身ok.csv"; //目标文件 CsvReader reader = new CsvReader(isr); //默认是逗号分隔符,UTF-8编码 CsvWriter writer =new CsvWrite(destFilePath,‘,‘,Charset.forName("GBK")); /* * readRecord()判断是否还有记录,getValues()读取当前记录,然后指针下移 */ reader.readRecord(); writer.writeRecord(reader.getValues()); //读取表头 while(reader.readRecord()){ stringList = reader.getValues(); writer.writeRecord(stringList ); } reader.close(); writer.close(); }catch(Exception ex){ ex.printStackTrace(); } }
时间: 2024-11-29 03:48:27