CsvReader,CsvWriter的使用以及解决中文乱码

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();
            }
    }
    
上一篇:Linux目录结构与文件权限——(五)


下一篇:X Window 程式设计