-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reader.java
38 lines (36 loc) · 1.11 KB
/
Reader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.io.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
public class Reader
{
private List<Coordinate> liveCells;
public Reader(String fileName){
this.read(fileName);
System.out.println(">> Reading File...SUCCESS");
}
private boolean read(String fileName){
liveCells = new ArrayList<Coordinate>();
boolean succeeded = false;
try{
BufferedReader bfr = new BufferedReader(new FileReader(new File(fileName)));
if(bfr.ready()){
String line;
while((line = bfr.readLine()) != null){
String[] coordinate = line.split(",");
int x = Integer.parseInt(coordinate[0]);
int y = Integer.parseInt(coordinate[1]);
liveCells.add(new Coordinate(x, y));
}
}
succeeded = true;
bfr.close();
return succeeded;
}catch(IOException e){
return false;
}
}
public List<Coordinate> getLiveCells(){
return this.liveCells;
}
}