java 导入导出CSV

/**
     * 实现了读取一个本地文件,然后写出到另一个文件
     * 
     * @param file csv文件(路径+文件)
     * @return
     */
    public static void importCsv(File file){
          
        BufferedReader br=null;
        BufferedWriter bw = null;
        try { 
            //输出流  
            FileOutputStream fos = new FileOutputStream(new File("C:/jtyh/export/newexport/CUST_tx_tmp.csv"));//guar trade tx
            // 写入bom头。微软的excel用这个,不会中文乱码
            byte[] uft8bom={(byte)0xef,(byte)0xbb,(byte)0xbf};
            fos.write(uft8bom);
            bw =new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));
            //生成csv的标题头
            bw.append("NODE_ID,CUST_NAME,FIRST_BRACH,CREDIT_BALANCE").append("\r");
            
            br = new BufferedReader(new FileReader(file));
            String line = ""; 
            while ((line = br.readLine()) != null) { 
                    bw.append(line).append("\r");
                }
            }
        }catch (Exception e) {
        }finally{
            if(br!=null){
                try {
                    br.close();
                    bw.close();
                    bw=null;
                    br=null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
 
    }


版权声明:本文为weixin_40673663原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。