Hi to all, I'm trying to read from a file, line by line, and parse out
the data, by using the line.split(" ") function, and I have a file that
has 8 entries total per line, which means that it supposed to read up
to , array[7], but for some reason, when I run it , it says array
outofboundaries. The only thing here that is to notice, is that the
value at 7 might be either a string or an empty string, can that be a
problem?
Thanks
Martin Gerner - 04 May 2006 19:10 GMT
Could you please copy-paste your code so that we can look at it?
ataanis@gmail.com wrote in news:1146763242.632744.176950
@j73g2000cwa.googlegroups.com:
> Hi to all, I'm trying to read from a file, line by line, and parse out
> the data, by using the line.split(" ") function, and I have a file that
[quoted text clipped - 4 lines]
> problem?
> Thanks

Signature
Martin Gerner
stocksami@earthlink.net - 04 May 2006 19:22 GMT
> Hi to all, I'm trying to read from a file, line by line, and parse out
> the data, by using the line.split(" ") function, and I have a file that
[quoted text clipped - 4 lines]
> problem?
> Thanks
Try using the trim method of the readLine before using split.
example:
String s = in.readLine.trim();
where in is a BufferedReader
stocksami@earthlink.net - 04 May 2006 19:25 GMT
stocks...@earthlink.net wrote:
> > Hi to all, I'm trying to read from a file, line by line, and parse out
> > the data, by using the line.split(" ") function, and I have a file that
[quoted text clipped - 12 lines]
>
> where in is a BufferedReader
Whoops,
should have been
String s = in.readLine().trim();
Eric Sosman - 04 May 2006 20:00 GMT
ataanis@gmail.com wrote On 05/04/06 13:20,:
> Hi to all, I'm trying to read from a file, line by line, and parse out
> the data, by using the line.split(" ") function, and I have a file that
[quoted text clipped - 3 lines]
> value at 7 might be either a string or an empty string, can that be a
> problem?
Yes: You are using a form of split() that discards
trailing empty strings; see the Javadoc. There's a two-
argument split() method that can be used to retain the
empty trailers; again, see the Javadoc.

Signature
Eric.Sosman@sun.com
Bruce Lee - 04 May 2006 20:10 GMT
> Hi to all, I'm trying to read from a file, line by line, and parse out
> the data, by using the line.split(" ") function, and I have a file that
[quoted text clipped - 4 lines]
> problem?
> Thanks
yep. an empty line will not be added
Bruce Lee - 04 May 2006 20:11 GMT
> Hi to all, I'm trying to read from a file, line by line, and parse out
> the data, by using the line.split(" ") function, and I have a file that
[quoted text clipped - 4 lines]
> problem?
> Thanks
that should be empty string will not be added