So basically I'm reading a text file that has a bunch of lines. I need to extract certain lines from the text file and add those specific lines into string array. I've been trying to split each newLine with: "\n" , "\r". This did not work. I keep getting this error as well:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 at A19010.main(A19010.java:47)
Here is the code:
Path objPath = Paths.get("dirsize.txt"); if (Files.exists(objPath)){ File objFile = objPath.toFile(); try(BufferedReader in = new BufferedReader( new FileReader(objFile))){ String line = in.readLine(); while(line != null){ String[] linesFile = line.split("\n"); String line0 = linesFile[0]; String line1 = linesFile[1]; String line2 = linesFile[2]; System.out.println(line0 + "" + line1); line = in.readLine(); } } catch(IOException e){ System.out.println(e); } } else { System.out.println( objPath.toAbsolutePath() + " doesn't exist"); }