Vikram Kumar wrote:
>
> Dear Friends,
>
> byte c;
> int i=0;
> do
> {
> i=fin.read();
> c=(byte)i;
> out.write(c);
>
> }
>
> while(i!=-1);
> fin.close();
Ugly code alert! Why do you read a byte, write a byte, loop? This is so wasteful
(and slow) that it is one of the few optimizations I would recommend be
performed during initial writing of the code.
As a rule, it is generally better to use a resource as much as possible before
switching to another resource. In this case, read as many bytes as possible
before writing any bytes. One way to do this is to use a BufferedInputStream.
Another way you could do it, if you can determine the number of bytes that need
to be read, is this way:
byte[] bArray = new byte[size];
int numBytesRead = fin.read(bArray); //puts all bytes into bArray with one
call
KMukhar
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html