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

/**
* 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();
}

你可能感兴趣的:(读取一个文件中的内容到String中)