-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTxtFileReader.java
50 lines (42 loc) · 1.06 KB
/
TxtFileReader.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
39
40
41
42
43
44
45
46
47
48
49
50
package at.tw.ose;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class TxtFileReader {
private BufferedReader reader;
private String text = "";
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
/**
* Creates a TxtFileReader with a FileReader wrapping the file object.
*
* @param File file to be written
* @throws IOException only propagated
*/
public TxtFileReader(File file) throws IOException {
reader = new BufferedReader(new FileReader(file));
String lineOfText = null;
do {
try {
// read in every line of the file separately
if ((lineOfText = reader.readLine()) != null) {
text = text.concat(lineOfText);
// depending on the OS, a \n or \r\n is added
text = text.concat(System.getProperty("line.separator"));
}
} catch (IOException e) {
e.printStackTrace();
}
} while (lineOfText != null);
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}