-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyIO.java
More file actions
101 lines (82 loc) · 2.68 KB
/
MyIO.java
File metadata and controls
101 lines (82 loc) · 2.68 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package userinterface;
import java.io.*;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Date;
public class MyIO {
private String[][] wordDataPackage = new String[2][1000];
private GregorianCalendar today = new GregorianCalendar();
private int year = today.get(Calendar.YEAR);
private int month = today.get(Calendar.MONTH) + 1;
private int day = today.get(Calendar.DAY_OF_MONTH);
private static MyIO i = null;
private int allWordsIndex = 0;
public String[] getWords() {
return wordDataPackage[0];
}
public String[] getNames() {
return wordDataPackage[1];
}
public static MyIO getMyIOInstance() throws IOException {
if (i == null)
i = new MyIO();
return i;
}
public static void finishWork(String[] modifiedWords, String[] wordsName) throws IOException {
int modifiedWordsIndex = 0;
while (modifiedWords[modifiedWordsIndex] != null) {
File f = new File(wordsName[modifiedWordsIndex]);
f.createNewFile();
BufferedWriter s = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8"));
s.write(modifiedWords[modifiedWordsIndex]);
s.close();
modifiedWordsIndex++;
}
}
private MyIO() throws IOException {
fillWordsToArray();
}
private void fillWordsToArray() throws IOException {
if (allWordsIndex == 0) {
File todayFileName = new File(combineInToString(year, month, day));
wordDataPackage[1][allWordsIndex] = combineInToString(year, month, day);
if (todayFileName.isFile())
wordDataPackage[0][allWordsIndex] = "1";
else
wordDataPackage[0][allWordsIndex] = "0";
allWordsIndex++;
}
if (today.compareTo(new GregorianCalendar(2017, 6, 0)) < 1)
return;
today.add(Calendar.DAY_OF_MONTH, -1);
String fileName = combineInToString(today.get(Calendar.YEAR), today.get(Calendar.MONTH) + 1,
today.get(Calendar.DAY_OF_MONTH));
File fileWord = new File(fileName);
if (fileWord.isFile()) {
BufferedReader f = new BufferedReader(new InputStreamReader(new FileInputStream(fileWord), "UTF-8"));
char[] c = new char[1000];
f.read(c);
f.close();
if (new String(c).indexOf(":", 0) != -1) {
String cc = new String(c);
cc = cc.substring(0, cc.indexOf("*") + 1);
wordDataPackage[0][allWordsIndex] = cc;
wordDataPackage[1][allWordsIndex] = fileName;
allWordsIndex++;
}
}
fillWordsToArray();
}
private static String combineInToString(int t0, int t1, int t2) {
String s1;
String s2;
t0 = t0 % 100;
s1 = "" + t1;
if (t1 < 10)
s1 = "0" + t1;
s2 = "" + t2;
if (t2 < 10)
s2 = "0" + t2;
return "C:/English/" + t0 + "_" + s1 + "_" + s2 + ".txt";
}
}