Android LineNumberReader Read readLineFromFile(File file)

Here you can find the source of readLineFromFile(File file)

Description

Read file to list of string.

Declaration

public static List<String> readLineFromFile(File file) 

Method Source Code

//package com.java2s;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*from  ww w. j  a  va 2  s  .c  o  m*/
     * Read file to list of string.
     * */
    public static List<String> readLineFromFile(File file) {
        List<String> result = new ArrayList<String>();
        LineNumberReader lnr = null;
        try {
            lnr = new LineNumberReader(new BufferedReader(
                    new InputStreamReader(new FileInputStream(file),
                            Charset.defaultCharset().name())));
            for (String line = lnr.readLine(); line != null; line = lnr
                    .readLine()) {
                result.add(line);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (lnr != null) {
                try {
                    lnr.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return result;
    }
}