-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageFile.java
More file actions
34 lines (29 loc) · 954 Bytes
/
Copy pathPageFile.java
File metadata and controls
34 lines (29 loc) · 954 Bytes
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
package javasearchengine.objects;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public final class PageFile {
public String data;
public PageFile(File f) {
data = readToString(f);
}
public String readToString(File file) {
String encoding = "UTF-8";
Long fileLength = file.length();
byte[] fileContent = new byte[fileLength.intValue()];
try {
try (FileInputStream fileInputStream = new FileInputStream(file)) {
fileInputStream.read(fileContent);
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
try {
return new String(fileContent, encoding);
} catch (UnsupportedEncodingException e) {
return null;
}
}
}