-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathHamletParser.java
More file actions
41 lines (30 loc) · 902 Bytes
/
HamletParser.java
File metadata and controls
41 lines (30 loc) · 902 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
35
36
37
38
39
40
41
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
/**
* Created by thook on 10/7/15.
*/
public class HamletParser {
private String hamletData;
public HamletParser(){
this.hamletData = loadFile();
}
private String loadFile(){
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("hamlet.txt").getFile());
StringBuilder result = new StringBuilder("");
try(Scanner scanner = new Scanner(file)){
while(scanner.hasNextLine()){
String line = scanner.nextLine();
result.append(line).append("\n");
}
scanner.close();
}catch(IOException e){
e.printStackTrace();
}
return result.toString();
}
public String getHamletData(){
return hamletData;
}
}