🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.java
Article #864

Re: just a quickie

#864
From: Tim Cross
Date: Sun, 02 Apr 2000 00:00
56 lines
2169 bytes
Greg,

I think your problem is you need to use the equals() method fo the
string class - you cannot compare strings with == or !=. Try something 
like

while (!(temp = in.readLine()).equals("")) // while line is not ""

Note that you may have another problem here - what happens when you
come to the end of the input file? Perhapse you could try something
like

while ((temp = in.readLine()) != null) {
        if (temp.equals(""))
                // do whatever you do if you get a blank line
        else
                // do whatever you do when you don't get a blank line
}

Hope this helps

Tim
"Greg" <gsimon@bigpond.net.au> writes:

> I have to read in a paragraph of text from a text file like the one shown
> below only the program has to stop reading on the blank line.
> 
> ================================
> blah blah blah
> hello hello
> 
> start of new paragraph
> ================================
> 
> this is what I have tried:
> 
> BufferedReader in = new BufferedReader(
>                                        new FileReader("file.txt"));
> String temp;
> 
> while((temp = in.readLine()) != "\n")   /* I have also tried ...!= "" */
> {
>    ......
> 
> could someone please tell me what to compare the String to, or where I am
> going wrong. any help appreciated.
> 
> Greg
> 
> 

-- 
Tim Cross
NorthNet Internet Services
mailto:tcross@northnet.com.au
phone:+61 2 6772 5973
Technical Details
Message-ID: <m3d7o86dw9.fsf@tim.northnet.com.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <S%dF4.1190$1b4.5128@news-server.bigpond.net.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,1e8f92126f62286c
X-Google-Attributes: gid10d6db,public
From: Tim Cross <tcross@tim.northnet.com.au>
Subject: Re: just a quickie
Date: 2000/04/02
Message-ID: <m3d7o86dw9.fsf@tim.northnet.com.au>
X-Deja-AN: 605584587
References: <S%dF4.1190$1b4.5128@news-server.bigpond.net.au>
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@telstra.net
X-Trace: nsw.nnrp.telstra.net 954668209 203.57.24.28 (Sun, 02 Apr 2000 19:36:49 EST)
Organization: Customer of Telstra Big Pond Direct
MIME-Version: 1.0
User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.6
NNTP-Posting-Date: Sun, 02 Apr 2000 19:36:49 EST
Newsgroups: aus.computers.java