码迷,mamicode.com
首页 > 编程语言 > 详细

java utf8字符 导出csv 文件的乱码问题。

时间:2014-07-01 14:16:46      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   文件   

在输出的格式为UTF-8的格式,但是打开CSV文件一直为乱码,后来参考了这里的代码,搞定了乱码问题,原文请参考:http://hbase.iteye.com/blog/1172200

      private static void writeBcp( ) throws IOException
      {
            //Create bcp file if not exist
                        File bcpFile = new File("test.csv");
                        //bcpFile.delete();
                        byte[] bom ={(byte) 0xEF,(byte) 0xBB,(byte) 0xBF};
                        //boolean newFile = false;
                        FileOutputStream bcpFileWriter = new FileOutputStream(bcpFile);
                        bcpFileWriter.write(bom);
                  //bcpFile.delete();
                        String title = "\"MD5\",\"扫描文件名\",\"扫描时间\"," +
                        "\"是否病毒\",\"安全等级\",\"病毒英文名称\"," +
                        "\"病毒变种\",\"病毒类型\",\"病毒影响\"," +
                        "\"感染系统\",\"传播方式\",\"备注\"";
                        
                        
                        bcpFileWriter.write((new String(title.getBytes(), "utf-8")).getBytes());
                        bcpFileWriter.write("\n".getBytes());
                        
                        String appStr = "\""+123+"\","
                        +"\""+123+"\","
                        +123+","
                        +123+","
                        +123+","
                        +"\""+123+"\","
                        +"\"\","
                        +123+","
                        +"\""+123+"\","
                        +"\""+123+"\","
                        +"\""+123+"\","
                        +"\""+123+"\"\n";
                        

                        bcpFileWriter.write(appStr.getBytes());
                        bcpFileWriter.close();
                        
      }

 

java utf8字符 导出csv 文件的乱码问题。,布布扣,bubuko.com

java utf8字符 导出csv 文件的乱码问题。

标签:style   blog   http   java   color   文件   

原文地址:http://www.cnblogs.com/tangkai/p/3818084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!