Cut last line

hi everyone. i've a problem. i've got a text file such as:

"first line

second line

third line

"

in the last line i have an empty line(enter pressed after third line), how can i cut this last line?

thank for any advice. best regards, i want achieve such as this:

"first line

second line

third line

"

[367 byte] By [alcatraz123a] at [2007-11-27 8:17:55]
# 1
Read three lines and write to output file.
Michael.Nazarov@sun.coma at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 2
nvmMessage was edited by: deAppel
deAppela at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 3
what does it mean message above? is this kind of humiliation?
alcatraz123a at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 4
while((lineSet = br_out.readLine())!=null)what should i change if i want to not to read this last empty line i've tried this but doesn't work. please helpwhile((lineSet = br_out.readLine())!=null||(lineSet.trim().indexOf("")>-1))
alcatraz123a at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 5

> what does it mean message above? is this kind of humiliation?

Touchy, touchy!

"nvm" means never mind. The poster saw he had duplicated the previous

post so he went back and edited his. That's all.

And I agree with the idea: read in the file and echo it, line by line, except for

the last line. Since you can't simultaneously read and write to a file

(unless it's a random access file, but that's asking for trouble with a text file),

write to a temporary file, then when you are done, delete the original file

and rename the temporary one.

Hippolytea at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 6

> while((lineSet = br_out.readLine())!=null||(lineSet.trim().indexOf("")>-1))

What if lines in the middle of the file are empty?

How big can the file be? 10 lines, 100 lines, 1,000 lines 1,000,000 lines?

If it's not too big, read the whole file into memory and go from there.

Hippolytea at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 7
i want only read this file without last line reading?while((line.readLine()?what should i write here?maybe this is very easy but i give up know
alcatraz123a at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 8

> i want only read this file without last line

> reading?

>

You can't. You have to read the last line, determine that you don't want it AFTER you've read it (because it's the last line or because it's empty) and then just not process it the way you're processing the others.

jverda at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 9
Prob solv?
Hippolytea at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 10

while(line = file.readLine() != null)

{

if(line.trim().length() > 0)

// write to the output file

else

//otherwise, ignore it

}

SomeoneElsea at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 11
> while(line = file.readLine() != null)> {>if(line.trim().length() > 0)> // write to the output file> > //otherwise, ignore itHave we determined the OP wants to filter out *all* empty lines?
Hippolytea at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 12

> > while(line = file.readLine() != null)

> > {

> >if(line.trim().length() > 0)

> > // write to the output file

> >

> > //otherwise, ignore it

>

> Have we determined the OP wants to filter out *all*

> empty lines?

No, but on the other hand, we don't know that he doesn't either. So any solution we give right now is a WAG.

~Tim

SomeoneElsea at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 13
WAG?nvm. Got it.Message was edited by: Hippolyte
Hippolytea at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...
# 14
wild *** guess
SomeoneElsea at 2007-7-12 20:03:21 > top of Java-index,Java Essentials,Java Programming...