Here you can find the source of readFile(String fileNm)
public static ArrayList<String> readFile(String fileNm)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { /**/*from w ww.j av a2 s. c o m*/ * * @param fileNm * @param encode - "utf-8" * @return */ public static ArrayList<String> readFile(String fileNm, String encode) { ArrayList<String> lines = null; InputStreamReader isr = null; BufferedReader br = null; try { isr = new InputStreamReader(new FileInputStream(fileNm), encode); br = new BufferedReader(isr); lines = new ArrayList<String>(); String line = null; while ((line = br.readLine()) != null) { lines.add(line); } } catch (Exception e) { e.printStackTrace(); } finally { if (isr != null) try { isr.close(); } catch (Exception ex) { } ; if (br != null) try { br.close(); } catch (Exception ex) { } ; } return lines; } public static ArrayList<String> readFile(String fileNm) { ArrayList<String> lines = null; FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(new File(fileNm)); br = new BufferedReader(fr); lines = new ArrayList<String>(); String line = null; while ((line = br.readLine()) != null) { lines.add(line); } } catch (Exception e) { e.printStackTrace(); } finally { if (fr != null) try { fr.close(); } catch (Exception ex) { } ; if (br != null) try { br.close(); } catch (Exception ex) { } ; } return lines; } }