Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-25-2007, 05:28 AM
Member
 
Join Date: Nov 2007
Posts: 6
peachyco is on a distinguished road
Reading a file for use
Hi, y'all!

I'm having some difficulty with storing information from my customer records. What happens after a transaction is the saving of the transaction in this format:

Code:
Customer No. Cashier Code yyyy/MM/dd HH.mm.ss (date and time stamped upon completion of transaction) <Item Code>:<Quantity Bought>:<Price Subtotal>:HH.mm.ss:<Flag if item was cancelled>
Now, at the start of the program, I must load this file to determine the last customer number assigned, so that the next customer will have the next customer no. in the sequence. My problem is how to read the file so that I can determine that last customer number. I was planning on using StreamTokenizer, but I'm unsure of how I'm gonna use it this time. Maybe read the customer numbers in an array/vector of integers and all others in an array/vector of Strings?

Here's a sample of the customer_records.dat file:

Code:
1 A0701 2007/11/01 11.32.10 1:2:10:2007/11/01 11.30.56: 3:1:5:2007/11/01 11.28.33: 9:3:15:2007/11/01 11.12.08:Cancelled 2 B0702 2007/11/01 15.00.02 5:5:25:2007/11/01 14.58.02:
Thanks in advance for any suggestion/comment/advice!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-26-2007, 04:16 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 112
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
I would use a BufferedReader. Look into it and if you need any help with it, post a reply
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-27-2007, 04:49 AM
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading a File into ByteArray Java Tip Java Tips 0 01-15-2008 04:19 PM
Reading a file mew New To Java 2 12-30-2007 01:23 PM
Reading text file Lennon-Guru New To Java 1 12-16-2007 12:38 AM
Reading a properties file peiceonly New To Java 5 08-09-2007 08:08 PM
Reading from a file leebee New To Java 1 07-23-2007 01:02 PM


All times are GMT +3. The time now is 08:03 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org