Java Text File Read Line readLines(File file)

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

Description

read Lines

License

Open Source License

Declaration

public static List<String> readLines(File file) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import com.google.common.collect.Lists;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static List<String> readLines(File file) throws IOException {
        return readLines(new FileInputStream(file), "UTF-8");
    }/*from   ww  w.  ja  va2 s . c  om*/

    public static List<String> readLines(InputStream stream) throws IOException {
        return readLines(stream, "UTF-8");
    }

    public static List<String> readLines(InputStream stream, String encoding) throws IOException {
        List<String> list = Lists.newArrayList();
        try (Scanner scanner = new Scanner(stream, encoding)) {
            while (scanner.hasNext()) {
                list.add(scanner.nextLine());
            }
        }
        return list;
    }
}

Related

  1. readLines(File file)
  2. readLines(File file)
  3. readLines(File file)
  4. readLines(File file)
  5. readLines(File file)
  6. readLines(File file)
  7. readLines(File file, boolean ignoreComments)
  8. readLines(File file, int maxArraySize)
  9. readLines(File file, String charset)