I have created a "Savings Account" so to speak and I need to be able to read the balance from a file I have called balance.txt The file is formatted like this
How do I get it to read only the numbers after "Balance: $"?****************************** Tue Jun 04 23:59:51 CDT 2013 ****************************** Balance: $999.99 ******************************
I am trying to do:
but it breaks the section of code where I write to the file.Scanner s = new Scanner("path to file"); if (s.hasNextDouble){ double balance = s.nextDouble(); }
Eclipse puts a red line under void and throws. If I take away the ; from the scanner declaration, writing to file is fixed but the if statement and the scanner declaration are borked.public void toFile() throws IOException{ String stars = "******************************"; String content = stars + "\n " + date.toString() + "\n" + stars + "\n Balance: $" + balance + "\n" + stars; File file = new File("path to file"); FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); }