Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 2941
19
  • 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: 21458
96
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: 21458
96
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!