d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Using A Filereader Java
Add Reply New Topic New Poll
Member
Posts: 24,101
Joined: Nov 8 2007
Gold: 5,561.70
Jul 23 2012 04:35pm
I'm trying to read in a small order form in java.

I don't exactly understand how you can read in specific parts of the txt file.

Like I'm trying to read in an order form something like this (it's contained in a .txt file), where the item name is listed with the date it was purchased.

Customer: Joe
Phone 1/1
Shoes 10/5
Candy 4/14
Phone 3/25
Toothbrush 7/5
Lamp 8/22

Kinda confused on how the FileReader accomplishes this.

I have to print out the customers named, followed by the amount he ordered and it's total cost.

Just don't know how it knows how to take in the correct information. :mellow:

This post was edited by lopelurag on Jul 23 2012 04:35pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jul 23 2012 04:53pm
the secret is that you read the whole file, then parse the string later.
Member
Posts: 24,101
Joined: Nov 8 2007
Gold: 5,561.70
Jul 23 2012 05:05pm
Quote (carteblanche @ Jul 23 2012 06:53pm)
the secret is that you read the whole file, then parse the string later.


Oh so you would turn it into a string then parse the information you need? What if you don't know what the user will input, does that even matter?

This is all done automatically and I'm confused about how to make sure the program parses the correct information.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jul 23 2012 05:20pm
Quote (lopelurag @ Jul 23 2012 07:05pm)
This is all done automatically and I'm confused about how to make sure the program parses the correct information.


assuming the format is guarenteed, it should be straight forward. looks like you have one line with the customer name. this is the only line that contains a colon. so if this line contains a colon, then everything to the right is the name.

every other line ends with X/X where X represents a number. so look for the last space to split the date from the product.

whats the problem?
Member
Posts: 24,101
Joined: Nov 8 2007
Gold: 5,561.70
Jul 23 2012 05:33pm
Quote (carteblanche @ Jul 23 2012 07:20pm)
assuming the format is guarenteed, it should be straight forward. looks like you have one line with the customer name. this is the only line that contains a colon. so if this line contains a colon, then everything to the right is the name.

every other line ends with X/X where X represents a number.  so look for the last space to split the date from the product.

whats the problem?


Yeah got it thanks, was having a brainfart. Wasn't difficult at all.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll