Here you can find the source of readFile(File file)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static LinkedList<String> readFile(File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; public class Main { /**/*from w w w .jav a2 s . com*/ * * @param file * @return * @throws IOException */ public static LinkedList<String> readFile(File file) throws IOException { LinkedList<String> ret = new LinkedList<String>(); FileInputStream fis = null; InputStreamReader isr = null; BufferedReader br = null; try { fis = new FileInputStream(file); isr = new InputStreamReader(fis); br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { ret.add(line); } } finally { try { if (br != null) { br.close(); } if (isr != null) { isr.close(); } if (fis != null) { fis.close(); } } catch (IOException e) { e.printStackTrace(); } } return ret; } }