• Post Reply Bookmark Topic Watch Topic
  • New Topic

not able to download file(error 500 lang.outof memory)

 
prashant komaragiri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
iam trying to download a file with the help of a servlet but i am getting error no .500. thank u in advance. Iused the following piece of code on click of a Button:

public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
try
{
System.out.println("helllo");
File file = new File("c:\\xml.doc");
FileInputStream fin = new FileInputStream(file);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream fout = new DataOutputStream(bout);
int i=0;
i = fin.available();
System.out.println(i);
int c=0;
byte bufin[] = new byte[i];
while(c!=-1)
{
fout.write(c);
}
byte bufout[] =bout.toByteArray();
ServletOutputStream sout = res.getOutputStream();
res.setContentType ("application/ms-word");
res.setHeader("Content-Disposition","attachment; filename=\"" + file.getName() + "\"");
res.setContentLength(bufout.length);
sout.write(bufout);
sout.flush();
sout.close();
fout.close();
fin.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!