• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading A File  RSS feed

 
Mark Captain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i am working on a program that has to read a file, save the variables, and write it to a new file in a different format. However I am having trouble saving each variable the way id like to.

The file I am reading is in this format.

firstname lastname
firstname lastname

I need to store the first name and last name as seperate variables, however I can only store each line as a variable by using this code



This results in both the first and last name being stored in firstName. Any idea how to fix this?
 
Jon Frank
Greenhorn
Posts: 5
Firefox Browser Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nextLine() will read an entire string up until the newline character.
This is a good place to use the split method.

 
Mark Captain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Jon! Very helpful!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!