Java DataInputStream Read readFromFileToLineArray(File file)

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

Description

read From File To Line Array

License

Apache License

Declaration

public static ArrayList<String> readFromFileToLineArray(File file) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.io.InputStreamReader;

import java.util.ArrayList;

public class Main {

    public static ArrayList<String> readFromFileToLineArray(File file) {
        System.out.println("Debug: full input File Name " + file);
        ArrayList<String> lines = new ArrayList<String>();

        // Open the file that is the first 
        // command line parameter
        FileInputStream fstream = null;
        try {/*  w  ww .j ava 2 s . c om*/
            fstream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        //Read File Line By Line
        try {
            while ((strLine = br.readLine()) != null) {
                lines.add(strLine);
                // Print the content on the console
                //System.out.println (strLine);
            }
            //Close the input stream
            in.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return lines;
    }
}

Related

  1. readBytes(File ff)
  2. readBytes(String filename)
  3. readBytes(String filename)
  4. readBytesArray(DataInputStream dis)
  5. readFromFile(File file)
  6. saveDoubleMatrixFromBinary(DataInputStream reader, int rows, int cols, PrintStream out)