blob: b19320e717577161e09709aa481d048a35f8e561 (
plain)
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
|
/**
* Simple util class to contain methods commonly used accross Java files
*/
package Compiler;
import java.io.*;
public class Utils {
// Adapted from here for now
// https://www.geeksforgeeks.org/different-ways-reading-text-file-java/
public static String readFile(String path) throws Exception{
File file = new File(path);
BufferedReader br = new BufferedReader(new FileReader(file));
// Stringbuilder is mutable
StringBuilder readFile = new StringBuilder();
String line;
while ((line = br.readLine()) != null)
//System.out.println(line);
readFile = readFile.append(line + "\n");
br.close();
return readFile.toString();
}
public static void main(String[] args) throws Exception {
String currentPath = new java.io.File(".").getCanonicalPath();
System.out.println("Util class testing");
try {
String helpfile = readFile("Compiler/helpfile.txt");
System.out.println("File read success");
}
catch (Exception e) {
System.out.println("File read failure");
}
}
}
|