Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Reading from a text file  RSS feed

 
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,
 
Rancher
Posts: 2974
20
  • 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.
 
Sheriff
Posts: 21464
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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: 21464
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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!