Java Text File Load loadTextFile(String filename)

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

Description

load Text File

License

Open Source License

Declaration

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

Method Source Code


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

import java.io.BufferedReader;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> loadTextFile(String filename) throws IOException {
        List<String> ls = new ArrayList<String>();
        String line = "";
        BufferedReader reader = null;
        try {/*from  w  ww.ja v a 2  s .com*/
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
            while ((line = reader.readLine()) != null) {
                // Traitement du flux de sortie de l'application si besoin est
                ls.add(line.trim());
            }
        } catch (FileNotFoundException fnfe) {
            System.err.println("Erreur fichier : " + filename + " indisponible");
            System.exit(1);
            return null;
        } catch (IOException ioe) {
            System.err.println("Erreur sur fichier : " + filename);
            ioe.printStackTrace();
            System.exit(1);
            return null;
        } finally {
            if (reader != null)
                reader.close();
        }
        return ls;
    }
}

Related

  1. loadTextFile(File textFile)
  2. loadTextFile(final String filePath)
  3. loadTextFile(String fileFullPath)
  4. loadTextFile(String fileName)
  5. loadTextFile(String fileName)
  6. loadTextFile(String filename, int maxLines)
  7. loadTextFileAsLines(String fileName)