*
The moose likes Java in General and the fly likes  scan.useDelimiter( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " scan.useDelimiter(",")" Watch " scan.useDelimiter(",")" New topic
Author

scan.useDelimiter(",")

Brett Freedman
Greenhorn

Joined: Feb 26, 2010
Posts: 13
I'm trying to read in a comma delimited file with Scanner. This works for me with the default space delimiter but I want to use comma since I have some team names with two words.

Here is my code:



Here is part of my input file:


Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Hi,

you must use , (comma) and \n (new line) as your delimiters, since lines are separated by new lines.
Try this:

Brett Freedman
Greenhorn

Joined: Feb 26, 2010
Posts: 13
Ireneusz Kordal wrote:Hi,

you must use , (comma) and \n (new line) as your delimiters, since lines are separated by new lines.
Try this:



Thanks, Ireneusz! This didn't entirely clear up my problem but got me going in the right direction. There were apparently some extra non-visible characters tacked onto the last field of each line mucking up the works. I ended up scanning in one line at a time, splitting that string into tokens and trimming the last field.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: scan.useDelimiter(",")
 
Similar Threads
loading a csv file
How do I read an entire file all at once?
also need help this code
String Comparison Problem.