Conor Crowe

Greenhorn
+ Follow
since Mar 03, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Conor Crowe

Thank you Dragos

I could not figure out how to remove or check if there is a new line character at the end of the file.
I changed the while loop as follows:



The file copied straight from the K&B book is as follows:

Donnie Darko/sci-fi/Gyllenhall, Jake
Raiders of the Lost Ark/action/Ford, Harrison
2001/sci-fi/??
Caddy Shack/comedy/Murray, Bill
Star Wars/sci-fi/Ford, Harrison
Lost in Translation/comedy/Murray, Bill
Patriot Games/action/Ford, Harrison

I suppose what I am really asking is why is a String read after the buffered reader reads a null value ?

when I print out the String values there are eight lines output but only seven lines in the file.
There are seven with length 3 and one with length 1.
Output:

Donnie Darko
sci-fi
Gyllenhall, Jake
3
Raiders of the Lost Ark
action
Ford, Harrison
3
2001
sci-fi
??
3
Caddy Shack
comedy
Murray, Bill
3
Star Wars
sci-fi
Ford, Harrison
3
Lost in Translation
comedy
Murray, Bill
3
Patriot Games
action
Ford, Harrison
3

1

Thanks
Hello,

I am trying to read in from a text file and enter the data into an ArrayList.
When I tokenize the data read in from the file, there seems to be a whitespace read in which causes an array out of bounds exception when the if clause (tokens.length ==3) is not used.
You can see from the output that an array of size 1 is read at the end of file.
Could someone please explain why it does this?

Thank you




output:

Donnie Darko
sci-fi
Gyllenhall, Jake
3
Raiders of the Lost Ark
action
Ford, Harrison
3
2001
sci-fi
??
3
Caddy Shack
comedy
Murray, Bill
3
Star Wars
sci-fi
Ford, Harrison
3
Lost in Translation
comedy
Murray, Bill
3
Patriot Games
action
Ford, Harrison
3

1
[Donnie Darko sci-fi Gyllenhall, Jake
, Raiders of the Lost Ark action Ford, Harrison
, 2001 sci-fi ??
, Caddy Shack comedy Murray, Bill
, Star Wars sci-fi Ford, Harrison
, Lost in Translation comedy Murray, Bill
, Patriot Games action Ford, Harrison
]