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
"
Read three lines and write to output file.
nvmMessage was edited by: deAppel
what does it mean message above? is this kind of humiliation?
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))
> 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.
> 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.
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
> 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 >

while(line = file.readLine() != null)
{
if(line.trim().length() > 0)
// write to the output file
else
//otherwise, ignore it
}
> 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?
> > 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
WAG?nvm. Got it.Message was edited by: Hippolyte