Here you can find the source of readFile(String fileName)
public static StringBuffer readFile(String fileName) throws FileNotFoundException
//package com.java2s; /************************************************************* * This file is part of CB2XML. /*from w w w . j av a 2s .c o m*/ * See the file "LICENSE" for copyright information and the * terms and conditions for copying, distribution and * modification of CB2XML. ************************************************************* */ import java.io.*; public class Main { public static StringBuffer readFile(String fileName) throws FileNotFoundException { InputStream fis = openFile(fileName); BufferedReader buffer = null; StringBuffer sb = new StringBuffer(); String s = null; try { buffer = new BufferedReader(new InputStreamReader(fis)); while ((s = buffer.readLine()) != null) { sb.append(s); } } catch (Exception e) { e.printStackTrace(); return null; } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { ; } } } return sb; } public static InputStream openFile(String fileName) throws FileNotFoundException { InputStream stream = ClassLoader.getSystemClassLoader().getResourceAsStream(fileName); if (stream == null) stream = new FileInputStream(fileName); if (stream == null) throw new FileNotFoundException("resources not found: " + fileName); return stream; } }