This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with tab delimited scanning

 
michael montalbano
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a project for CSC220 that requires me to write a program that can read 35 different first names, last names, and email addresses from a text file. I am then to take these names and input them in a format that has the first name, last name, and email address seperate from eachother. I know how to read from the text file, but I can't figure out to make it so I can assign the first name to name1, the last name to name2, and the address to email. Instead, i've only been able to get it to print out all of it at once. can anyone point me in the right direction? It would be much appreciated
 
Claudiu Chelemen
Ranch Hand
Posts: 75
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and welcome!

I don't see where the problem is, since you already got the data from the file.
Could you please post the code you've got so far ?

You may store the data for each person in a simple pojo, eg. PersonView, in order to create a collection of these PersonViews.
Then you can manipulate the data in any way needed.

Cheers
Claudiu
 
Stephan van Hulst
Bartender
Pie
Posts: 5432
52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to take a look at the Scanner class. It can break Strings up in so called tokens. By default, each token is considered to be everything separated by whitespace, which should be perfect for your problem.

Specifically, take a look at the methods hasNext() and next(), in the Scanner class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic