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:

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.

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 :)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.