Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading from a text file  RSS feed

 
Mark Miranda
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I'm pretty new to Java and I was wondering, how can I split this from a text file? I would like to store each line into an array of Strings.

First Name: John
Last Name: Doe
Street: 555 dust way
City: New York
Zip: 12453
Phone: 234-213-4321
Email: jdoe@yahoo.com

This is how I would like the output to be:

String[] line = new String[7];

line[0] = "John"
line[1] = "Doe"
line[2] = "555 dust way"
line[3] = "New York"
line[4] = "12453"
line[5] = "234-213-4321"
line[6] = " jdoe@yahoo.com"

Thanks,
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go ahead and try it.

If you have a problem then post your SSCCE showing the problem.
 
Mark Miranda
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:Go ahead and try it.

If you have a problem then post your SSCCE showing the problem.


sure, thanks.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like reading the file one line at a time and then using String.indexOf would do the trick.
 
Mark Miranda
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Sounds like reading the file one line at a time and then using String.indexOf would do the trick.


Thanks, Rob! I started using delimiters, but I will give your suggestion a try.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!