//Sample04_02.java import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.UnsupportedEncodingException; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; class Sample04_02{ public static void main(String[] args){ String path = "hello.txt"; File file = new File(path); ArrayList list = null; try { BufferedReader br = new BufferedReader( new InputStreamReader( new FileInputStream(file), "UTF-8" ) ); list = new ArrayList(); String strLine; while((strLine = br.readLine()) != null) { list.add(strLine); } br.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } if(list!=null){ for(String str : list){ System.out.println(str); } }else{ System.out.println("null"); } } }