设为首页 加入收藏

TOP

JavaIO读取文件中文乱码问题
2014-11-13 23:00:07 】 浏览:5004
Tags:JavaIO 读取 文件 中文 乱码 问题

  1、JAVA读取文件,避免中文乱码。


  /**


  * 读取文件内容


  *


  * @param filePathAndName String 读取文件路径


  * @return String 文件中的内容


  */


  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;


  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Java中执行顺序 下一篇用JAXB实现JAVA对象与XML文件的绑..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目