Java Scanner Read readFile(String file_name)

Here you can find the source of readFile(String file_name)

Description

read File

License

Open Source License

Declaration

public static ArrayList<String> readFile(String file_name) 

Method Source Code

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

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

import java.util.ArrayList;

import java.util.Scanner;

public class Main {
    public static ArrayList<String> readFile(String file_name) {
        /* kamus */
        ArrayList<String> list = null;
        Scanner scanner;/*from   w w  w .ja v a  2 s .c o  m*/

        /* algoritma */

        try {
            // inisialisasi varibel
            list = new ArrayList<String>();
            scanner = new Scanner(new FileInputStream(file_name));

            // proses baca tiap baris
            while (scanner.hasNext()) {
                list.add(scanner.nextLine());
            }

            // close stream
            scanner.close();
        } catch (FileNotFoundException ex) {
            // JOptionPane.showMessageDialog(null, "Utils->readFile() ERROR! " + file_name, "Error", JOptionPane.ERROR_MESSAGE);
            //Logger.getLogger(FileImportUtils.class.getName()).log(Level.SEVERE, null, ex);
            return null;

        }

        return list;
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File input)
  4. readFile(File path)
  5. readFile(final File f)
  6. readFile(String filename)
  7. readFile(String fileName)
  8. readFile(String fileName)
  9. readFile(String fileName)