-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileWork.java
More file actions
64 lines (53 loc) · 1.59 KB
/
FileWork.java
File metadata and controls
64 lines (53 loc) · 1.59 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
package lastYear;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
public class FileWork {
private BufferedReader br;
private PrintWriter pw;
public boolean openInputFile(String fileName) {
try {
br = new BufferedReader(new FileReader(fileName));
return true;
} catch (IOException e) {
return false;
}
}
public boolean openOutputFile(String fileName) {
try {
pw = new PrintWriter(fileName);
return true;
} catch (IOException e) {
return false;
}
}
public void closeOutputFile() {
pw.close();
}
public String read() throws IOException, ClassNotFoundException {
String s;
StringBuilder sb = new StringBuilder();
while ((s = br.readLine()) != null) {
sb.append(s);
}
return sb.toString();
}
public void outputSortAlph(ArraysString arrays) throws IOException {
arrays.sortAlphabet();
for (ArrayComponents item : arrays.getList()) {
pw.println(item.getName());
}
}
public void outputSortNumElem(ArraysString arrays) throws IOException {
arrays.sortNumElements();
for (ArrayComponents item : arrays.getList()) {
pw.println(item.getName() + " " + item.getNumberEl());
}
}
public void outputCapacity(ArraysString arrays) throws IOException {
for (ArrayComponents item : arrays.getList()) {
pw.println(item);
}
}
}