`
jxqc_job
  • 浏览: 529 次
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
JAVA读写文件如何避免中文乱码 java读写文件如何避免中文乱码 http://zhidao.baidu.com/question/2073995085632361068.html
/*** 读取文件内容** @param filePathAndName
* String 如 c://1.txt 绝对路径
* @return boolean*/public static String readFile(String filePathAndName) {
String fileContent = "";try {File f = new File(filePathAndName);
if(f.isFile()&&f.exists()){
InputStreamReader read = new InputStreamReader(new FileInputStream(f),"UTF-8");
BufferedReader reader=new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
fileContent += line;}read.close();}} catch (Exception e) {
System.out.println("读取文件内容操作出错");
e.printStackTrace();}return fileContent;}
Global site tag (gtag.js) - Google Analytics