标签:eclipse java bufferedwriter 中文
最近遇到了一个小麻烦,就是在eclipse环境中读写UTF-8格式的txt文件时很正常,但是当导出成jar包后,通过点击来读写文件时出现了部分中文乱码问题。
解决办法:
开始时用的是FileReader和FileWriter来读写的,后来改成用InputStreamReader和OutputStreamWriter后问题解决
关键代码:
BufferedReader reader; BufferedWriter writer; //reader = new BufferedReader(new FileReader(new File(filedir,filename))); reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filedir,filename)),"UTF-8")); //writer = new BufferedWriter(new FileWriter(new File(filedir,emailDomain+".txt"),true)); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(filedir,emailDomain+".txt"),true),"UTF-8"));
(PS:不用管代码中的具体文件路径和文件名,看懂思路即可)
本文出自 “zifangsky” 博客,请务必保留此出处http://983836259.blog.51cto.com/7311475/1661761
解决eclipse中java项目导出成jar包后读写UTF-8文件中文乱码问题
标签:eclipse java bufferedwriter 中文
原文地址:http://983836259.blog.51cto.com/7311475/1661761