Hey There..
I'm having a problem occurring within my code.
I have a txt file containing jibberish called testingfile.txt
testingfile.txt contains:
hithere34|where 293|21|3|9
heythere5|where 633|25|4|9
hellothere66|where 918|21|7|9
Now when the 'List' button is clicked I want it to just print in the console the data within the testingfile.txt (I want it to print out in the console so I know that it is being called).
I tried this but it keeps throwing an IOException.. :
public myGrades() { initComponents(); txtAreaActions number = new txtAreaActions(); btnList.addActionListener(number); } public class txtAreaActions implements ActionListener { public void actionPerformed(ActionEvent e) { try { if (e.getSource() == btnList) { Scanner scanner = new Scanner(new File("testingfile.txt")); scanner.useDelimiter("\\|, \\s, "); while (scanner.hasNextLine()) { String s = scanner.next(); parseRecord(s); } scanner.close(); } } catch (IOException error) { System.out.println("Error"); } } } public void parseRecord(String record) { Scanner recIn = new Scanner(record); recIn.useDelimiter("\\|, \\s"); String area1 = recIn.next(); String area2 = recIn.next(); int num1 = Integer.parseInt(recIn.next()); int num2= Integer.parseInt(recIn.next()); int num3 = Integer.parseInt(recIn.next()); double total = (num1 / num2) * num3; System.out.println(area1 + area2); System.out.printf("%.2f%n", total); }
Any clues?
Thanks!