Android Text File Read read(String pathName)

Here you can find the source of read(String pathName)

Description

read

Declaration


public static List<String> read(String pathName) 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static List<String> read(String pathName) {

        if (pathName != null) {

            try {

                return readFree(new File(pathName));

            } catch (FileNotFoundException e) {
                e.printStackTrace();/*  w ww.j  a v a2 s  . com*/
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return null;
    }

    public static List<String> read(File file) {

        if (file != null) {

            try {

                return readFree(file);

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return null;
    }

    private static List<String> readFree(File file) throws IOException {

        List<String> archive = new ArrayList<String>();

        BufferedReader reader = new BufferedReader(new FileReader(file));

        String s;

        do {
            s = reader.readLine();
            if (s != null) {
                archive.add(s);
            }
        } while (s != null);

        reader.close();

        return archive;
    }
}

Related

  1. read(File file)
  2. read(File file)
  3. read(File file, boolean raw)
  4. read(String file)
  5. read(String fileName)
  6. readCipherSuites(String file)
  7. readClasspathTextFile(String filename)
  8. readFile(File file)
  9. readFile(File file)