Java Text File Read Line readLines(String file, ArrayList lines)

Here you can find the source of readLines(String file, ArrayList lines)

Description

read Lines

License

Apache License

Declaration

public static void readLines(String file, ArrayList<String> lines) 

Method Source Code


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

import java.util.*;

import java.io.*;

public class Main {
    public static void readLines(String file, ArrayList<String> lines) {
        BufferedReader reader = null;
        try {//from w  w w . j av  a 2  s.co  m

            reader = new BufferedReader(new FileReader(new File(file)));

            String line = null;
            while ((line = reader.readLine()) != null) {
                lines.add(line);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

    public static void readLines(String file, HashSet<String> lines) {
        BufferedReader reader = null;

        try {

            reader = new BufferedReader(new FileReader(new File(file)));

            String line = null;
            while ((line = reader.readLine()) != null) {
                lines.add(line.trim());
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

  1. readlines(final File file)
  2. readLines(int problemNumber)
  3. readLines(String body)
  4. readLines(String file)
  5. readLines(String file)
  6. readLines(String filename)
  7. readLines(String fileName)
  8. readlines(String filename)
  9. readLines(String filename)