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相加的方式解决。

  • 相关阅读:
    线程池问题
    高级I/O
    闹钟设计
    线程竞争问题
    线程基本函数
    SpringMvc支持跨域访问
    gitlab qq邮件配置
    gitlab断电
    docker run always
    电子书网
  • 原文地址:https://www.cnblogs.com/lijc1990/p/3482470.html
Copyright © 2011-2022 走看看