Hello, I am fairly new to Java and I'm working on some code that is supposed to open a file and copy each line into an array. But the problem is that it returns an IOException and doesn't complete the task. The code is below:
Any help will be appreciated.import java.util.*; import java.io.*; public class test { static String[] subjects = {}; public static void main(String[] args) { loadArrays(); } public static void loadArrays() { String subFile = "data/subjects.txt"; try { subjects = readLines(subFile); } catch(IOException e) { System.out.println("cant"); } } public static String[] readLines(String filename) throws IOException { FileReader fileReader = new FileReader(filename); BufferedReader bufferedReader = new BufferedReader(fileReader); List<String> lines = new ArrayList<String>(); String line = null; while((line = bufferedReader.readLine()) != null) { lines.add(line); } bufferedReader.close(); return lines.toArray(new String[lines.size()]); } }