🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #15973

Re: File IO.

#15973
From: Chris Hill
Date: Mon, 12 Apr 1999 00:00
113 lines
3265 bytes
As I indicated in my other post, you can't use an Integer parameter as
an out parameter.  The Integer value remains 0 because Read doesn't
change the value of tmp1 in Clean.  Unless you are planning to add
more logic to Read and Write, I wouldn't even bother writing your own
functions.  Just call read and write correctly.

I would change it to look like this:

  public void Clean()
  {
    int tmp = 0;

    try
    {
      while (tmp != -1)
      {
        tmp = fin.read();
        // process tmp
        fout.write(tmp);
      }//end while
    }
    catch(IOException e)
    {
      // handle other errors here
    }
  }//end Clean()

On Sun, 11 Apr 1999 20:56:01 -0700, "Jason C. Leach"
<leachjc@hotmail.com> wrote:

>hi,
>
>I'm having a little trouble w/ file IO. In specific, detecting the end
>of file.  Here is my code segment that does the reading and writing.
>What it will do is convert a file (in the end) but for now I just make a
>copy of the file to see that I am doing it correctley. What it does is
>keep writing. I read in a 2MB file and it merrely passes the 2MB mark on
>the output file, so I terminate it.
>
>Here is the segment:
>fin is a FileInputStream
>fout is a FileOutputStream
>
>  public void Read(Integer tmp) //read in a byte from my file.
>  {
>     try
>    {
>      tmp = new Integer(fin.read());
>    }
>    catch (IOException e)
>    {
>    }
>
>  return;
>  }
>//-----------------------------------------------------------------------------
>
>  public void Write(Integer tmp) //write a byte to my output file.
>  {
>    try
>    {
>      fout.write(tmp.intValue());
>    }
>    catch (IOException e)
>    {
>    }
>
>  return;
>  }
>//-----------------------------------------------------------------------------
>
>//-----------------------------------------------------------------------------
>
>  public void Clean() //this will eventually be the algorythm to clean
>up the file.
>                                //for now it should make a copy.
>  {
>    /* variable declerations */
>    Integer tmp1 = new Integer(0);  //shoud be set to NULL or ZERO
>    Integer tmp2 = new Integer(0);  //shoud be set to NULL or ZERO
>
>    Read(tmp1); //fetch first byte
>    //Read(tmp2); //fetch second byte
>    //do while not End Of File; should be -1 to indicate EOF
>    while ( /* (tmp1.intValue() != -1) */ tmp2.intValue() != -1)
>    {
>      Write(tmp1);
>      Read(tmp1);
>    }
>    }//end while
>    //Write(tmp1);
>
>  }//end Clean()
>
>//---------------------------------
>
>Thanks,
>    Jason
>--
>
>
>�,+���+,��,+���+,�*
>....Jason C. Leach
>..."Many Hands Make Light Work."
>..- Unknown
>
>-- PGP key on server: pgpkeys.mit.edu
>
>
>

Chris Hill
Chris244@aol.com
Technical Details
Message-ID: <37117152.2342028258@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37116ED0.EE5262B1@hotmail.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f74b3,409689455649c9cf
X-Google-Attributes: gidf74b3,public
From: Chris244@aol.com (Chris Hill)
Subject: Re: File IO.
Date: 1999/04/12
Message-ID: <37117152.2342028258@forums.borland.com>
X-Deja-AN: 465342494
References: <37116ED0.EE5262B1@hotmail.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language