Java tutorial
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { public static synchronized ArrayList<String> readFile(String filename) { BufferedReader buffreader; ArrayList<String> lines = null; FileInputStream is; BufferedReader reader; File file = new File(filename); if (file.exists()) { lines = new ArrayList<String>(); try { is = new FileInputStream(file); reader = new BufferedReader(new InputStreamReader(is)); String line = reader.readLine(); int i = 0; while (line != null) { lines.add(line); // System.out.println(line); line = reader.readLine(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return lines; } }