Java File to Text Line fileToLines(File file)

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

Description

file To Lines

License

Open Source License

Declaration

static List<String> fileToLines(File file) 

Method Source Code


//package com.java2s;
//    it under the terms of the GNU General Public License as published by

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import java.util.LinkedList;
import java.util.List;

public class Main {
    static List<String> fileToLines(File file) {
        List<String> lines = new LinkedList<String>();
        String line = "";
        try {/*from  w  w  w.jav  a  2s  .  co  m*/
            BufferedReader in = new BufferedReader(new FileReader(file));
            while ((line = in.readLine()) != null) {
                lines.add(line);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return lines;
    }

    static List<String> fileToLines(String filename) {
        List<String> lines = new LinkedList<String>();
        String line = "";
        try {
            BufferedReader in = new BufferedReader(new FileReader(filename));
            while ((line = in.readLine()) != null) {
                lines.add(line);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return lines;
    }
}

Related

  1. fileToLines(String filename)
  2. fileToLines(String filename)
  3. fileToLines(String fileName)
  4. fileToLines(String filePath)