Java ANSI转码UTF-8
2024-10-20 18:58:26
public static void change(String filepath) throws UnsupportedEncodingException, IOException{
BufferedReader buf = null;
OutputStreamWriter pw=null;
String str = null;
String allstr=""; //用于输入换行符的字节码
byte[] c=new byte[2];
c[0]=0x0d;
c[1]=0x0a;
String t=new String(c); buf=new BufferedReader(new InputStreamReader(new FileInputStream(filepath), "GBK"));
while((str = buf.readLine()) != null){
allstr=allstr+str+t;
} buf.close(); pw =new OutputStreamWriter(new FileOutputStream(filepath),"UTF-8");
pw.write(allstr);
pw.close();
}
尝试用了StringBuffer进行内容的存储,结果乱码,原因待查。最后使用String相加的方式解决。
最新文章
- cf723a The New Year: Meeting Friends
- Hibernate Spring
- 跟我学Windows Azure 五 使用Cloub Service连接Blob Service完成图片的上传
- [git]添加项目到git
- java 方法调用绑定
- PHP 5:PHP语法导向
- Spring Boot--war发布
- setinIerval和setTimeout的区别?
- Python 实现 动态规划 /斐波那契数列
- day29 类中的内置函数方法 __str__ __repr__ __call__ isinstance() issubclass()
- 百度地图sdk---pc端
- Django商城项目笔记No.11用户部分-QQ登录1获取QQ登录网址
- poj3017 Cut the Sequence 单调队列 + 堆 dp
- alpha冲刺阶段博客集合
- c#截取图片
- mac 上 sublime text2 快捷键
- winfrom 底层类 验证码
- JSON/JSONP浅谈
- C# -- 泛型(3)
- eslint 人性化配置