View Single Post
  #3 (permalink)  
Old 11-27-2007, 04:49 AM
staykovmarin staykovmarin is offline
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
You can read the file backwards, until you find a number that is a normal Double num:
Code:
BufferedReader reader = new BufferedReader(new FileReader( "cashTest")); String s; StringBuilder tmp = new StringBuilder(); while ((s = reader.readLine()) != null) { tmp.append(s.toLowerCase() + "\n"); } double num = 0.0; String[] arr = tmp.toString().split("\n"); // read the array backwards, starting with the last line for (int i = arr.length - 1; i >= 0; i--) { try { num = Double.valueOf(arr[i]); // if the number cannot be converted to a Double, it would mean that it is one of the other lines // if it can be converted, then break out of the for loop break; } catch (NumberFormatException e) { // just for a test mess System.out.println("Not on this line"); } } // just to make sure that the value we got was greater than 0 if (num > 0) System.out.println(num); else System.out.println("No customer records found. A possible error occured");

Last edited by staykovmarin : 11-27-2007 at 04:53 AM.
Reply With Quote