-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.java
More file actions
35 lines (27 loc) · 794 Bytes
/
Utils.java
File metadata and controls
35 lines (27 loc) · 794 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
package mainPackage;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Utils {
public static String loadFileAsString(String path) {
StringBuilder builder = new StringBuilder(); //allows adding to a string
try {
BufferedReader br = new BufferedReader(new FileReader(path));
String line; //current line of file
while((line = br.readLine()) != null)
builder.append(line + "\n");
br.close();
}catch(IOException e) {
e.printStackTrace(); //promts error to screen
}
return builder.toString();
}
public static int parseInt(String number) {
try {
return Integer.parseInt(number);
}catch(NumberFormatException e) {
e.printStackTrace();
return 0;
}
}
}