We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,659 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Reading Array's from .txt files Help

Hello everyone or anyone!
Could some please assist me on how to read a text file like this:

ProgrammingAssignment1Data.txt

123 South Market Street
Downtown 101
Package
0

1599 Burbank Road
Cinema 10
Movie posters in tubes
1

1 order slip format is:
Pick up address
Drop off address
item description
order number

I am trying to read the file to put each slip in an array. Any advice!
Thanks in advance!:cool:

4
Contributors
3
Replies
9 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
justin08
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

One of the easier classes to use for reading text files is the Scanner class.
Use an array for putting what is read into an array.

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

I'm not gonna give you the correct answer as I can see this is an assignment and I do want you to learn for youself, but I can give you the process.
Just think of it, how many and which characters are truly in this file?
Remember, for each new line, there's a "\n" in the end of that line. Using this, you can read the entire contents of the file (using the Scanner class as NormR1 said).
Then you use that and split the string into an array. Hint; Only on one place in this array there's a "\n\n" sequence.

By splitting at the "\n\n" you'll get an array of 2, with 1 slip in each element.
I copied your assignment above and I can confirm this process works. PM me if you need more help, hope I was clear enough :)

Zhoot
Light Poster
26 posts since Jan 2008
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 0

or, read the file line by line, create a simple object OrderSlip which will contain all the info for one orderslip and, if you know up front how many orders you will have, create an array of orderslips in which you store the info, otherwise, add them to a list which takes only OrderSlips as elements.

stultuske
Industrious Poster
4,369 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0652 seconds using 2.7MB