Java Scanner Read readFileToList(File file)

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

Description

read File To List

License

Open Source License

Declaration

public static List<String> readFileToList(File file) 

Method Source Code


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

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static List<String> readFileToList(File file) {
        ArrayList<String> list = new ArrayList<>();

        try {/*w  w w  . j a  v  a2 s.c  om*/
            Scanner scan = new Scanner(file);

            while (scan.hasNextLine()) {
                list.add(scan.nextLine());
            }
        } catch (FileNotFoundException ex) {
            return null;
        }

        return list;
    }
}

Related

  1. readFile(String filePath)
  2. readFile(String path)
  3. readFile(String pathname)
  4. readFile(String project, boolean judge)
  5. readFileFully(InputStream stream)
  6. readFileWithoutComments(File input)
  7. readFromReader(Scanner scanner)
  8. readFromScanner(Scanner scanner)
  9. readInt(String prompt)