In the Solution the input from the reader was first store in e regular String bevor adding to the list, why is that necessary?
I check my code with the Debugger and the Lines will add separate to the ArraList, as the task required...
So what i don't see?
Please give me a hint. :)
package de.codegym.task.task15.task1525;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/*
Datei in einem statischen Block
*/
public class Solution {
public static List<String> lines = new ArrayList<>();
public static File FILE_NAME = new File("data.txt");
public static BufferedReader fileReader;
static {
try {
fileReader = new BufferedReader(new FileReader(FILE_NAME));
while (fileReader.ready()) {
lines.add(fileReader.readLine());
}
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println(lines);
}
}