Java BufferedReader Read readFile(String filename, boolean print)

Here you can find the source of readFile(String filename, boolean print)

Description

read File

License

Open Source License

Declaration

public static List<String> readFile(String filename, boolean print) 

Method Source Code


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

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

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

public class Main {
    public static List<String> readFile(String filename, boolean print) {
        List<String> data = new ArrayList<String>();

        BufferedReader br = null;
        String line = null;/*  w  ww . j  ava2  s. c  om*/
        StringBuilder sb = new StringBuilder();
        try {

            br = new BufferedReader(new FileReader(filename));

            line = br.readLine();
            if (line != null) {
                data.add(line);
                for (String retval : line.split(";")) {
                    if (print)
                        System.out.print(retval + "  ");
                }
            }
            System.out.println();
            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
                if (line != null) {
                    if (line.equals("") == false)
                        data.add(line);

                    for (String retval : line.split(";")) {
                        if (print)
                            System.out.print(retval + "  ");
                    }
                    if (print)
                        System.out.println();
                }
            }
            //           String everything = sb.toString();

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return data;

    }
}

Related

  1. readFile(String filename)
  2. readFile(String fileName)
  3. readfile(String filename)
  4. readFile(String FileName)
  5. readFile(String fileName)
  6. readFile(String filename, boolean skipEmptyLine)
  7. readFile(String fileName, String basePath)
  8. readFile(String fileName, String commentFlag)
  9. readFile(String fileName, String commentFlag)