forked from siavash2012/Digital-Credentials-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextIO.java
More file actions
74 lines (53 loc) · 1.76 KB
/
TextIO.java
File metadata and controls
74 lines (53 loc) · 1.76 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*The code is implemented by Siavash Khalaj (skhal045@uottawa.ca)*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class TextIO {
String[] wordsArray;
ArrayList<String> fileDataArray = new ArrayList<>();
FileWriter writer;
public TextIO(String fileName) {
try {
writer = new FileWriter(fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
public void write(long time) throws IOException {
writer.write(Integer.toString((int)time) + "\t");
}
public void write(String input) throws IOException {
writer.write(input);
}
public void close() throws IOException {
writer.close();
}
public void readTestFile(String fileName) {
try {
BufferedReader buf = new BufferedReader(new FileReader(fileName));
ArrayList<String> words = new ArrayList<>();
String lineJustFetched = null;
while (true) {
lineJustFetched = buf.readLine();
if (lineJustFetched == null) {
break;
} else {
wordsArray = lineJustFetched.split("\t");
for (String each : wordsArray) {
if (!"".equals(each)) {
words.add(each);
}
}
}
}
for (String each : words) {
fileDataArray.add(each);
}
buf.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}