summaryrefslogtreecommitdiffstats
path: root/src/Compiler/Utils.java
diff options
context:
space:
mode:
authorchris.sutcliffe <ctd.sutcliffe@gmail.com>2021-11-28 23:21:57 +0000
committerchris.sutcliffe <ctd.sutcliffe@gmail.com>2021-11-28 23:21:57 +0000
commitc78d48e6bf79a01bfe1d43ebafbfedd1a64129cd (patch)
tree5257ade82cd23791f53cfc1511aa574006a6431f /src/Compiler/Utils.java
parent8badb0fab61a23dd81466c3f5f8aadd77bf952e3 (diff)
downloadesotericFORTRAN-c78d48e6bf79a01bfe1d43ebafbfedd1a64129cd.tar.gz
esotericFORTRAN-c78d48e6bf79a01bfe1d43ebafbfedd1a64129cd.zip
add util class for reading files and change filereading method
Diffstat (limited to 'src/Compiler/Utils.java')
-rw-r--r--src/Compiler/Utils.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Compiler/Utils.java b/src/Compiler/Utils.java
new file mode 100644
index 0000000..f9bd41c
--- /dev/null
+++ b/src/Compiler/Utils.java
@@ -0,0 +1,39 @@
+/**
+ * Simple util class to contain methods commonly used accross Java files
+ */
+package Compiler;
+
+import java.io.*;
+import java.nio.file.Files;
+
+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");
+
+ return readFile.toString();
+ }
+
+ public static void main(String[] args) throws Exception {
+ String currentPath = new java.io.File(".").getCanonicalPath();
+ System.out.println("Current dir:" + currentPath);
+
+ String helpfile = readFile("Compiler/helpfile.txt");
+ System.out.println(helpfile);
+
+ }
+
+
+}