i use the code below to read a text file.
try {
BufferedReader in = new BufferedReader(new
FileReader("infilename"));
String str;
while ((str = in.readLine()) != null) {
process(str);
}
in.close();
} catch (IOException e) {
}
but when the file has a NEWLINE at the END ....the code also read that.
i just dont want to read that NEWLINE as soon as i come to the end.
what i have to do ?
>but when the file has a NEWLINE at the END ....the code also read that.
>
>i just dont want to read that NEWLINE as soon as i come to the end.
you mean you are getting a "" on the tail end of the file?
You may have multiple nls on the end of your file. Check with a hex
editor and chop them.
You may also just ignore 0-length lines.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
gk - 04 Apr 2006 05:28 GMT
>You may have multiple nls on the end of your file.....Check with a hex editor and chop them.
cant i do it by programatically ?
can i chop before reading the file by programatically ? How ?
Roedy Green - 04 Apr 2006 06:04 GMT
>can i chop before reading the file by programatically ? How ?
You can write a tidier that chops blank lines off the tail end of the
file. Whenever you read a blank line, increment a counter. Whenever
you hit an non blank line, emit counter blank lines , zero the counter
then emit the line.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
> i use the code below to read a text file.
>
[quoted text clipped - 14 lines]
>
> what i have to do ?
If you know that you will never have a line in your data that is empty
then just ignore it;
while ((str = in.readLine()) != null) {
if (!str.equals(""))
process(str);

Signature
Knute Johnson
email s/nospam/knute/
gk - 05 Apr 2006 02:09 GMT
I think this will look like much more impressive
while ((str = in.readLine()) != null &&(!str.equals("")) {
//if (!str.equals(""))
process(str);
Thnak you
Gordon Beaton - 05 Apr 2006 08:23 GMT
> I think this will look like much more impressive
>
> while ((str = in.readLine()) != null &&(!str.equals("")) {
> //if (!str.equals(""))
> process(str);
If your goal is to impress, why stop there when you can put
*everything* in the loop header?
while ((str = in.readLine()) != null && (!str.equals("") && (process(str) || true)));
/gordon
(See also http://www.m-w.com/cgi-bin/dictionary?va=irony)

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Roedy Green - 05 Apr 2006 09:07 GMT
>process(str) || true
what a strange way to code.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Gordon Beaton - 05 Apr 2006 09:29 GMT
> what a strange way to code.
Follow the link I posted.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
gk - 11 Apr 2006 11:57 GMT
I apologige , if the adjective has hurt you. I understand, that was the
improper usage after all. english is not my native language.
I wanted to mean, how the code looks like if i put that way. Of course,
the code has been borrowed from you but customized.
language should not taken into account.
thank you