-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReader.java
36 lines (32 loc) · 1.05 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
package org.thehuglio;
import java.io.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class Reader {
// stores all the data out of a text file (every line is added in the list, every empty line will be an empty string -> "")
List<String> data = new LinkedList<>();
// the file name/location
File file;
// starts the datareader and assigns the file
public Reader(File file) {
this.file = file;
datareader();
}
// reads the data out of the file
private void datareader() {
try {
LineNumberReader reader = new LineNumberReader(new FileReader(file));
for(int i = 0;i <= (reader.getLineNumber());i++)
{
data.add(reader.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// removes the last index (the last index will be a null so won't have anything to do with the file
data.remove(data.size()-1);
}
}
}