Ok, I know this is a really rookie question, but I looked around online a lot and am yet unable to find the answer to my question:
How can I read input from a file line by line in java?
Assume a file input that has integers on each line, like:
1
2
3
4
5
Here's the snippet of code I am trying to work with:
public static void main(File fromFile) {
BufferedReader reader = new BufferedReader(new FileReader(fromFile));
int x, y;
//initialize
x = Integer.parseInt(reader.readLine().trim());
y = Integer.parseInt(reader.readLine().trim());
}
Presumably, this would read in the first two lines and store them as integers in x and y. So going off the example, x=1, y=2.
It is finding a problem with this, and I don't know why.