Android Text File Read read(File file)

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

Description

read

Declaration


public static List<String> read(File file) 

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 a  2s  . co m*/
            } 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. fileToSet(final String dirname, final String filename, final Set set)
  2. getFileContent(File file)
  3. getFileContent(File file, String charSet)
  4. getFileResourceText(String path)
  5. read(File file)
  6. read(File file, boolean raw)
  7. read(String file)
  8. read(String fileName)
  9. read(String pathName)