Re: Detecting eof
This is a multi-part message in MIME format.
------=_NextPart_000_020A_01C6D515.0C45AC40
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Try this.
boolean eof;
eof = false;
try {
while (! eof) {
String str = in.readLine();
if (str == null) {
eof = true;
} else {
System.out.println(str);
}
}
} catch (Exception e) {
System.err.println ("Error: " + e.getMessage());
}
--
---------------------
Jason Herald
www.cingular.com
<jack.smith.sam@gmail.com> wrote in message =
news:1157932738.942299.159170@b28g2000cwb.googlegroups.com...
Hi All,
I am using this segment to read a file:
String str
while ((str=in.readLine()!=eof)
but I get error because of eof (I want to detect end of file). How can
I use it?
Also is there any way to detect blank lines in a file? for example:
a
b
If I read the second line is it equal to null or something elase?
Thanks for your help
Jack
------=_NextPart_000_020A_01C6D515.0C45AC40
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; =
charset=iso-8859-1">
<META content="MSHTML 6.00.5384.31" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Try this.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>boolean eof;</FONT></DIV>
<DIV><FONT face=Arial size=2>eof = false;</FONT></DIV>
<DIV><FONT face=Arial size=2>try {</FONT></DIV>
<DIV><FONT face=Arial size=2> while (! eof) =
{</FONT></DIV>
<DIV><FONT face=Arial =
size=2> String
str = in.readLine();</FONT></DIV>
<DIV><FONT face=Arial size=2> =
if (str ==
null) {</FONT></DIV>
<DIV><FONT face=Arial size=2>
eof = true;</FONT></DIV>
<DIV><FONT face=Arial size=2> } =
else
{</FONT></DIV>
<DIV><FONT face=Arial
size=2> &nbs=
p;
System.out.println(str);</FONT></DIV>
<DIV><FONT face=Arial size=2>
}</FONT></DIV>
<DIV><FONT face=Arial size=2> }</FONT></DIV>
<DIV><FONT face=Arial size=2>} catch (Exception e) {</FONT></DIV>
<DIV><FONT face=Arial =
size=2> System.err.println ("Error:
" + e.getMessage());</FONT></DIV>
<DIV><FONT face=Arial size=2>}</FONT> </DIV>
<DIV><FONT face=Arial size=2> </FONT></DIV>
<DIV><BR>-- <BR>---------------------<BR>Jason Herald<BR><A
href="http://www.cingular.com">www.cingular.com</A><BR></DIV>
<DIV><<A
href="mailto:jack.smith.sam@gmail.com">jack.smith.sam@gmail.com</A>>=
wrote in
message <A
href="news:1157932738.942299.159170@b28g2000cwb.googlegroups.com">news:=
1157932738.942299.159170@b28g2000cwb.googlegroups.com</A>...</DIV>Hi
All,<BR><BR>I am using this segment to read a file:<BR><BR>String =
str<BR>while
((str=in.readLine()!=eof)<BR><BR>but I get error because of eof (I =
want to
detect end of file). How can<BR>I use it?<BR>Also is there any way to =
detect
blank lines in a file? for example:<BR>a<BR><BR>b<BR>If I read the =
second line
is it equal to null or something elase?<BR><BR>Thanks for your
help<BR>Jack<BR></BODY></HTML>
------=_NextPart_000_020A_01C6D515.0C45AC40--