Java Utililty Methods Text File Read Line

List of utility methods to do Text File Read Line

Description

The list of methods to do Text File Read Line are organized into topic(s).

Method

String[]readLines(String filename)
Read all lines of a file.
return readLines(new File(filename));
ListreadLines(String filename)
Returns a list of text lines from the specified file.
List<String> lines = new ArrayList<String>();
BufferedReader in = new BufferedReader(new FileReader(filename));
String line;
while ((line = in.readLine()) != null) {
    lines.add(line);
in.close();
return lines;
...
String[]readLines(String filename)
read Lines
FileReader fileReader = new FileReader(filename);
BufferedReader bufferedReader = new BufferedReader(fileReader);
List<String> lines = new ArrayList<String>();
String line = null;
while ((line = bufferedReader.readLine()) != null) {
    lines.add(line);
bufferedReader.close();
...
String[]readLines(String fileName)
read Lines
return readLines(new FileInputStream(fileName));
String[]readLines(String filename)
read Lines
List<String> result = new ArrayList<String>();
BufferedReader br = new BufferedReader(new FileReader(filename));
String strLine;
while ((strLine = br.readLine()) != null) {
    result.add(strLine);
br.close();
return result.toArray(new String[result.size()]);
...
ListreadLines(String fileName)
read Lines
List<String> lines = new ArrayList<String>();
try (InputStream in = new FileInputStream(fileName);
        BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
    String line = null;
    while ((line = br.readLine()) != null) {
        lines.add(line);
return lines;
ListreadLines(String filename)
Read the lines of a file into a list of strings, with each line represented as its own string.
List<String> lines = Lists.newArrayList();
try {
    BufferedReader in = new BufferedReader(new FileReader(filename));
    String line;
    while ((line = in.readLine()) != null) {
        if (line.trim().length() > 0) {
            lines.add(line);
    in.close();
} catch (IOException e) {
    throw new RuntimeException(e);
return lines;
ArrayListreadLines(String fileName)
read Lines
BufferedReader reader;
try {
    reader = openReader(fileName);
} catch (IOException e1) {
    System.out.println("Couldn't read file " + fileName);
    return null;
String line;
...
ListreadLines(String filename)
Just return each line of the file as String
ArrayList<String> retval = new ArrayList<String>();
try {
    BufferedReader in = new BufferedReader(new FileReader(filename));
    String curLine = in.readLine();
    while (curLine != null) {
        retval.add(curLine.trim());
        curLine = in.readLine();
    return retval;
} catch (IOException ioe) {
    System.out.println(String.format("Bad file(name): %s\n", ioe.toString()));
    return null;
LinkedListreadLines(String filename)
read Lines
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename), ENCODING));
LinkedList<String> lines = new LinkedList<String>();
while (true) {
    String line = reader.readLine();
    if (line == null)
        break;
    if (line.length() == 0)
        continue;
...