java读取文件内容的函数

2014-11-23 17:43:03 · 作者: · 浏览: 17

  public static String readFile(String fileName) {


  String output = "";


  File file = new File(fileName);


  if (file.exists()) {


  if (file.isFile()) {


  try {


  BufferedReader input = new BufferedReader(new FileReader(


  file));


  StringBuffer buffer = new StringBuffer();


  String text;


  while ((text = input.readLine()) != null)


  buffer.append(text + "\n");


  output = buffer.toString();


  } catch (IOException ioException) {


  System.err.println("File Error!");


  }