🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.java
Article #863

Re: just a quickie

#863
From: moz
Date: Sun, 02 Apr 2000 00:00
43 lines
1542 bytes
Greg wrote:

> 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

Dear Greg,

What I think your problem is, is that you shouldn't be using the operators
:==, != ...
try using:

    while(!temp.equals("\n")){
        .............
        .........
        ............
    }

I forget the exact reason that the !=/== thing doesn't work for strings, I
just remeber it doesn't.

Moz
Technical Details
Message-ID: <38E6BE82.AB340C1E@iinet.net.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: moz <moz@iinet.net.au>
Subject: Re: just a quickie
Date: 2000/04/02
Message-ID: <38E6BE82.AB340C1E@iinet.net.au>
X-Deja-AN: 605509094
Content-Transfer-Encoding: 7bit
References: <S%dF4.1190$1b4.5128@news-server.bigpond.net.au>
Content-Type: text/plain; charset=us-ascii
X-Trace: news.iinet.net.au 954645728 23739 SEy4sa@203.59.92.147
MIME-Version: 1.0
Newsgroups: aus.computers.java