-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReader.java
More file actions
38 lines (30 loc) · 803 Bytes
/
Copy pathFileReader.java
File metadata and controls
38 lines (30 loc) · 803 Bytes
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
/**
* @author Hubert
*/
public class FileReader {
private final String[] fileText;
public FileReader(String fileName) throws java.io.IOException {
String temp = "";
java.io.FileReader fileReader;
fileReader = new java.io.FileReader(fileName);
for (int i = fileReader.read(); i != -1; i = fileReader.read())
temp += (char) i;
fileReader.close();
fileText = temp.split("\\n");
length = fileText.length;
}
private int lineNumber = -1;
public final int length;
public String readNextLine() throws EndOfFileException {
try {
return fileText[++lineNumber];
} catch (ArrayIndexOutOfBoundsException e) {
throw new EndOfFileException("Reached end of file.");
}
}
}
class EndOfFileException extends Exception {
public EndOfFileException(String s) {
super(s);
}
}