Article View: borland.public.jbuilder.java.language
Article #15965File IO.
From: Jason C. Leach
Date: Sun, 11 Apr 1999 00:00
Date: Sun, 11 Apr 1999 00:00
77 lines
2471 bytes
2471 bytes
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
Technical Details
Message-ID:
<37116ED0.EE5262B1@hotmail.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f74b3,409689455649c9cf,start X-Google-Attributes: gidf74b3,public From: "Jason C. Leach" <leachjc@hotmail.com> Subject: File IO. Date: 1999/04/11 Message-ID: <37116ED0.EE5262B1@hotmail.com> X-Deja-AN: 465333825 Content-Transfer-Encoding: 8bit X-Accept-Language: en Content-Type: text/plain; charset=iso-8859-1 Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language