zoukankan      html  css  js  c++  java
  • Java ANSI转码UTF-8

     1 public static void change(String filepath) throws UnsupportedEncodingException, IOException{
     2     BufferedReader buf = null;
     3     OutputStreamWriter pw=null;        
     4     String str = null;
     5     String allstr="";
     6         
     7     //用于输入换行符的字节码
     8     byte[] c=new byte[2];
     9         c[0]=0x0d;
    10         c[1]=0x0a;
    11         String t=new String(c);
    12         
    13         buf=new BufferedReader(new InputStreamReader(new FileInputStream(filepath), "GBK"));
    14         while((str = buf.readLine()) != null){
    15             allstr=allstr+str+t;
    16         }
    17         
    18         buf.close();        
    19 
    20         pw =new OutputStreamWriter(new FileOutputStream(filepath),"UTF-8");
    21         pw.write(allstr); 
    22         pw.close();
    23     }

      尝试用了StringBuffer进行内容的存储,结果乱码,原因待查。最后使用String相加的方式解决。

  • 相关阅读:
    java内存泄露
    hbase java api
    配置CRT远程登录
    kafka分区消费模型
    JAVA内存区域
    JVM分代和垃圾回收
    spring中bean的作用域
    分布式RPC
    session共享
    ZooKeeper实现分布式session
  • 原文地址:https://www.cnblogs.com/lijc1990/p/3482470.html
Copyright © 2011-2022 走看看