Java File to Text Line fileToLines(String filename)

Here you can find the source of fileToLines(String filename)

Description

file To Lines

License

Open Source License

Declaration

public static List<String> fileToLines(String filename) throws IOException 

Method Source Code

//package com.java2s;
/****************************************************************************
 * Copyright (c) 2008-2014 Matthew Ballance and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from ww w.j a  v  a 2 s.  c  om*/
 *     Matthew Ballance - initial implementation
 ****************************************************************************/

import java.io.BufferedReader;

import java.io.FileReader;
import java.io.IOException;

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

public class Main {
    public static List<String> fileToLines(String filename) throws IOException {
        List<String> lines = new LinkedList<String>();
        String line = "";
        BufferedReader in = new BufferedReader(new FileReader(filename));
        while ((line = in.readLine()) != null) {
            lines.add(line);
        }
        in.close();
        return lines;
    }
}

Related

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