|
|
@@ -1,20 +1,44 @@
|
|
1
|
1
|
package rocks.zipcode;
|
|
2
|
2
|
|
|
3
|
|
-import java.io.IOException;
|
|
|
3
|
+import java.io.*;
|
|
4
|
4
|
|
|
5
|
5
|
/**
|
|
6
|
6
|
* @author leon on 16/11/2018.
|
|
7
|
7
|
*/
|
|
8
|
8
|
public class AlphaCharDocument extends Document {
|
|
|
9
|
+
|
|
|
10
|
+private FileWriter fw;
|
|
|
11
|
+private String fileName;
|
|
|
12
|
+private File file = new File(fileName);
|
|
|
13
|
+
|
|
9
|
14
|
public AlphaCharDocument(String fileName) throws IOException {
|
|
10
|
15
|
super(fileName);
|
|
|
16
|
+ this.fileName = fileName;
|
|
|
17
|
+ fw = new FileWriter(fileName);
|
|
11
|
18
|
}
|
|
12
|
19
|
|
|
13
|
20
|
@Override
|
|
14
|
21
|
public void write(String contentToBeWritten) {
|
|
|
22
|
+ try {
|
|
|
23
|
+ isAlpha(contentToBeWritten);
|
|
|
24
|
+ fw.write(contentToBeWritten);
|
|
|
25
|
+ } catch (IOException ex) {
|
|
|
26
|
+ ex.printStackTrace();
|
|
|
27
|
+ }
|
|
15
|
28
|
}
|
|
16
|
29
|
|
|
17
|
|
- private Boolean isAlpha(String s) {
|
|
|
30
|
+ public String read() throws FileNotFoundException {
|
|
|
31
|
+ BufferedReader br = new BufferedReader(new FileReader(file));
|
|
|
32
|
+ try {
|
|
|
33
|
+ return br.readLine();
|
|
|
34
|
+ } catch (IOException e) {
|
|
|
35
|
+ e.printStackTrace();
|
|
|
36
|
+ }
|
|
18
|
37
|
return null;
|
|
19
|
38
|
}
|
|
|
39
|
+
|
|
|
40
|
+ private void isAlpha(String s) throws IOException {
|
|
|
41
|
+ if(!s.matches("[a-zA-Z\\s]*"))
|
|
|
42
|
+ throw new IllegalArgumentException();
|
|
|
43
|
+ }
|
|
20
|
44
|
}
|