Win a copy of Kotlin for Android App Development this week in the Kotlin 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 3000
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: 21610
101
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: 21610
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Are you okay? You look a little big. Maybe this tiny ad will help:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!