Android File to String Read readFileOfList(String path)

Here you can find the source of readFileOfList(String path)

Description

read File Of List

Declaration

public static List<String> readFileOfList(String path) 

Method Source Code

//package com.java2s;

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> readFileOfList(String path) {
        List<String> list = new ArrayList<String>();
        InputStreamReader ir = null;
        BufferedReader br = null;
        try {// w w w .j  ava 2 s  .  c o m
            ir = new InputStreamReader(new FileInputStream(path), "UTF8");
            br = new BufferedReader(ir);
            String data = br.readLine();

            while (data != null) {
                if (!"".equals(data)) {
                    list.add(data);
                }
                data = br.readLine();
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (ir != null) {
                try {
                    ir.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
        return list;
    }
}

Related

  1. getStringArrayFromFile(File inputFile)
  2. getStringFromFile(File inputFile)
  3. fromFile(File f)
  4. readFile(String path)