Java InputStreamReader Read readFile(File file)

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

Description

read File

License

Open Source License

Declaration

public static ArrayList<String> readFile(File file) 

Method Source Code


//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.ArrayList;

public class Main {
    public static ArrayList<String> readFile(File file) {
        return readFile(file, "UTF8");
    }//from   w ww .ja  v a2 s .  co  m

    public static ArrayList<String> readFile(File file, String encoding) {
        ArrayList<String> lines = new ArrayList<String>(50);
        if (!file.exists()) {
            throw new IllegalStateException("Unable to find File " + file + " bye");
        } //if
        String line;
        boolean end = false;
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
            while (!end) {
                line = br.readLine();
                if (line == null) {
                    end = true;
                } else {
                    lines.add(line);
                }
            } //while
            br.close();
        } //try
        catch (IOException ioe) {
            System.err.println("Unable to open file");
            System.exit(-1);
        }
        return lines;
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(File file)
  5. readFile(File file)
  6. readFile(File file)
  7. readFile(File file)
  8. readFile(File file)
  9. readFile(File file)