zoukankan      html  css  js  c++  java
  • java utf8字符 导出csv 文件的乱码问题。

    在输出的格式为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("
    ".getBytes());
                            
                            String appStr = """+123+"","
                            +"""+123+"","
                            +123+","
                            +123+","
                            +123+","
                            +"""+123+"","
                            +""","
                            +123+","
                            +"""+123+"","
                            +"""+123+"","
                            +"""+123+"","
                            +"""+123+""
    ";
                            
    
                            bcpFileWriter.write(appStr.getBytes());
                            bcpFileWriter.close();
                            
          }
  • 相关阅读:
    在其他对象上同步
    如何在一个线程环境中使用一个线程非安全的java类
    原子类
    Volatile
    Spring中的设计模式2
    Spring中的设计模式
    Struts2中的设计模式
    Struts2中的设计模式----ThreadLocal模式
    享元模式(Flyweight)
    Java类加载器的工作原理
  • 原文地址:https://www.cnblogs.com/tangkai/p/3818084.html
Copyright © 2011-2022 走看看