|
|
@@ -12,22 +12,24 @@ import java.util.Scanner;
|
|
12
|
12
|
public class Document implements DocumentInterface {
|
|
13
|
13
|
|
|
14
|
14
|
private final FileWriter fw;
|
|
15
|
|
- // private final File file;
|
|
|
15
|
+ private final BufferedReader br;
|
|
|
16
|
+ private final File file;
|
|
16
|
17
|
|
|
17
|
18
|
public Document(String fileName) throws IOException {
|
|
18
|
19
|
this(new File(fileName));
|
|
19
|
20
|
}
|
|
20
|
21
|
|
|
21
|
22
|
public Document(File file) throws IOException {
|
|
22
|
|
- // this.file = file;
|
|
|
23
|
+ this.file = file;
|
|
23
|
24
|
this.fw = new FileWriter(file);
|
|
|
25
|
+ this.br = new BufferedReader(new FileReader(file));
|
|
24
|
26
|
}
|
|
25
|
27
|
|
|
26
|
28
|
@Override
|
|
27
|
29
|
public void write(String contentToBeWritten) {
|
|
28
|
30
|
try {
|
|
29
|
31
|
fw.write(contentToBeWritten);
|
|
30
|
|
- fw.close();
|
|
|
32
|
+ fw.flush();
|
|
31
|
33
|
} catch (IOException ex) {
|
|
32
|
34
|
ex.printStackTrace();
|
|
33
|
35
|
}
|
|
|
@@ -35,17 +37,6 @@ public class Document implements DocumentInterface {
|
|
35
|
37
|
|
|
36
|
38
|
@Override
|
|
37
|
39
|
public void write(Integer lineNumber, String valueToBeWritten) {
|
|
38
|
|
-// Scanner scanner = null;
|
|
39
|
|
-// try {
|
|
40
|
|
-// scanner = new Scanner(file);
|
|
41
|
|
-// } catch (FileNotFoundException e) {
|
|
42
|
|
-// e.printStackTrace();
|
|
43
|
|
-// }
|
|
44
|
|
-// StringBuilder sb = new StringBuilder();
|
|
45
|
|
-// while(scanner.hasNextLine()){
|
|
46
|
|
-// sb.append(scanner.nextLine());
|
|
47
|
|
-// }
|
|
48
|
|
-// String content = sb.toString();
|
|
49
|
40
|
|
|
50
|
41
|
}
|
|
51
|
42
|
|
|
|
@@ -56,7 +47,15 @@ public class Document implements DocumentInterface {
|
|
56
|
47
|
|
|
57
|
48
|
@Override
|
|
58
|
49
|
public String read() throws FileNotFoundException {
|
|
59
|
|
- return null;
|
|
|
50
|
+ String result="";
|
|
|
51
|
+ try{
|
|
|
52
|
+ String st;
|
|
|
53
|
+ while ((st = br.readLine()) != null)
|
|
|
54
|
+ result += st;}
|
|
|
55
|
+ catch (IOException e){
|
|
|
56
|
+ System.out.println("File not found for buffered reader.");
|
|
|
57
|
+ }
|
|
|
58
|
+ return result;
|
|
60
|
59
|
}
|
|
61
|
60
|
|
|
62
|
61
|
@Override
|