-
Notifications
You must be signed in to change notification settings - Fork 1
/
Loader.java
52 lines (42 loc) · 1.15 KB
/
Loader.java
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
package com.yurii.salimov.lesson05.task03;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* @author Yuriy Salimov ([email protected])
* @version 1.0
*/
public final class Loader {
private final String path;
private String text;
public Loader(final String path) {
this(path, "");
}
public Loader(final String path, final String text) {
this.path = path;
this.text = text;
}
public String read() throws IOException {
try (RandomAccessFile in = new RandomAccessFile(path, "r")) {
byte[] buf = new byte[(int) in.length()];
in.read(buf);
this.text = new String(buf);
return this.text;
}
}
public void write() throws IOException {
try (RandomAccessFile out = new RandomAccessFile(path, "rw")) {
byte[] buf = text.getBytes();
out.setLength(0);
out.write(buf);
}
}
public String getPath() {
return this.path;
}
public String getText() {
return this.text;
}
public void setText(final String text) {
this.text = text;
}
}