/** * 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); } }