-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileResource.java
More file actions
50 lines (39 loc) · 1.03 KB
/
Copy pathFileResource.java
File metadata and controls
50 lines (39 loc) · 1.03 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
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
/**
* Created by yury on 10/01/16.
*/
public class FileResource {
private File file ;
FileResource(){
}
public FileResource(File f) {
file = f;
}
public FileResource(String filename){
this(new File(filename));
}
public String asString(){
try {
return new String(Files.readAllBytes(file.toPath()));
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
public java.lang.Iterable<java.lang.String> lines() throws IOException {
return Files.readAllLines(file.toPath());
}
public java.lang.Iterable<java.lang.String> words() throws IOException {
String[] arr = asString().split("[\\s\\t\\n]+");
return Arrays.asList(arr);
}
public static void main(String args[])
{
new FileResource("file");
}
}