Java InputStreamReader Read readFileIntoLines(File file)

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

Description

Reads a file into a list of Strings

License

BSD License

Parameter

Parameter Description
file a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static List<String> readFileIntoLines(File file) 

Method Source Code

//package com.java2s;
/**//w w  w .  j a v a 2 s .  c o m
 * <p>
 * Utilities for manipulating Paths, Files, Directories, etc.
 * </p>
 * <p>
 * <span class="BSDLicense"> This software is distributed under the <a
 * href="http://hci.stanford.edu/research/copyright.txt">BSD License</a>.</span>
 * </p>
 * 
 * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu)
 */

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Reads a file into a list of Strings
     * 
     * @param file
     * @return
     * @throws IOException
     */
    public static List<String> readFileIntoLines(File file) {
        List<String> lines = new ArrayList<String>();
        try {
            FileInputStream fis = new FileInputStream(file);
            BufferedReader read = new BufferedReader(new InputStreamReader(fis));

            String line;
            while ((line = read.readLine()) != null) {
                lines.add(line);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return lines;
    }
}

Related

  1. readFileData(String directoryLocation, String fileName)
  2. readFileFromClassPath(String file)
  3. readFileFromDisk(String filepath)
  4. readFileFromResource(@SuppressWarnings("rawtypes") Class refClass, String filePath)
  5. readFileFromResource(String filename)
  6. readFileIntoLinesOfLongs(File file)
  7. readFileLineByLine(final File filePath)
  8. readFileList(File file)
  9. readFileOneLine(String filename, String keyInLine)