您的位置:首页 > 其它

读取一个文件中的内容到String中

2012-11-07 22:06 267 查看
/**
* readFileContent把json文件中的内容读取到一个String中返回
* @param   name
* @param  @return    设定文件
* @return String    DOM对象
* @Exception 异常对象
* @创建人: MaJian
* @创建时间:2012-11-7 下午12:57:00
* @修改人: MaJian
* @修改时间:2012-11-7 下午12:57:00
* @修改备注:
*/
private String readFileContent(String fileName) throws IOException {

 File file = new File(fileName);
  

 BufferedReader bf = new BufferedReader(new FileReader(file));
 String content = "";
 StringBuilder sb = new StringBuilder();
 while(content != null){
  content = bf.readLine();
  
  if(content == null){
   break;
  }
  sb.append(content.trim());
 }
 
 bf.close();
 return sb.toString();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐