Nur Azie

Greenhorn
+ Follow
since Jul 31, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nur Azie

OutputStream out=response.getOutputStream();

FileInputStream fin=null;
BufferedInputStream fBuf=null;

try
{

fin=new FileInputStream("logo.gif");
fBuf=new BufferedInputStream(fin);
final int BufferLen=2048;
byte[] buf=new byte[BufferLen];
int bytesRead;

while(-1!=(bytesRead=fBuf.read(buf,0,buf.length)))
{
out.write(buf,0,bytesRead);
}

out.flush();
out.close();

}
catch(FileNotFoundException fnfe)
{

fnfe.printStackTrace();
}
catch(Exception e)
{
;
e.printStackTrace();
}

finally
{
if (fBuf!=null) fBuf.close();

if (fin!=null) fin.close();
}


I have changed the code as above. Is that correct?
17 years ago
One more thing ... is the code written enough to cater exeption thrown
during run time error ? eg connection down, network down etc


tq
17 years ago
Thanks Peter ...
You mean I have to check "out" whether it null or not for the first time?

OutputStream out= null;
out = response.getOutputStream();


Is this correct? The rest follow as the existing code ...

Actually this is done in servlet ... Sometimes it hang or shut down the server.
Any idea with the code I written?


tq
17 years ago
I have a problem in read and display my image file in servlet
Below is my code ... Any help if this code is not correct.

OutputStream out=response.getOutputStream();

FileInputStream fin=null;
BufferedInputStream fBuf=null;

try
{

fin=new FileInputStream("logo.gif");
fBuf=new BufferedInputStream(fin);
final int BufferLen=2048;
byte[] buf=new byte[BufferLen];
int bytesRead;

while(-1!=(bytesRead=fBuf.read(buf,0,buf.length)))
{
out.write(buf,0,bytesRead);
}

if (out!= null) {

out.flush();
out.close();

}
}
catch(FileNotFoundException fnfe)
{

fnfe.printStackTrace();
}
catch(Exception e)
{
;
e.printStackTrace();
}

finally
{
if (fBuf!=null) fBuf.close();

if (fin!=null) fin.close();
}





thanks
17 years ago