reading from text file produces extra s p a c e s, even on numbers 1 0 1
I have a test.txt file with the following in it:
Code :
MapTile,1,256,false
MapTile,9,291,false
no matter what way I try to read this file in java, the result is:
Code :
M a p T i l e , 1 , 2 5 6 , f a l s e
M a p T i l e , 9 , 2 9 1 , f a l s e
String tokens[] = line.split("[,]"); //results in the following:
" M a p T i l e ", " 1 ", " 2 5 6 ", " f a l s e "
when the following is expected:
"MapTile", "1", "256", "false"
treating it to any method of removing all the white spaces fail, what exactly are these characters?
there is no way i can use the numbers or booleans in this (read as strings)
console says:
NumberFormatException: for input String: "2 5 6"
and goes on to specify the line where I try to
int num = Integer.parseInt(tokens[2]);
I have searched the net for hours on this.
Please help.
Re: reading from text file produces extra s p a c e s, even on numbers 1 0 1
Can you show the code you are using to read the file.
Add a println to print out the String that was read immediately after it is read to show what was read from the file.
How did you create the txt file? Can it contain unicode characters vs ASCII?
Do a properties on the file and see how many bytes the file contains. Does the byte count match the character count?
Re: reading from text file produces extra s p a c e s, even on numbers 1 0 1
never mind I rebuilt my loader and my parser works perfect now!
unicode, specified it in the writer but not the reader...
using IOOperations.java sub class from Java programming for the absolute beginner, it did not have Unicode Specified on both the writer and the reader. I fixed that, and it now works.