I'm still stumped here. I must be missing something obvious. I've attached my code below.
I am attempting to open a pdf or
doc file from the local file system. When the link is clicked on I get the dialogue box asking my to save or open the application. However, when it opens I see what appears to be raw data. Something like this:
�� ��� � > ��
for
word docs and a "damaged file" messagee for pdf files.
HttpSession session = req.getSession();
Upload upload = (Upload)session.getAttribute("uploadRef");
//resp.setContentType ("application/doc");
//resp.setContentType ("application/pdf");
resp.setContentType ("application/x-download");
resp.addHeader ("Content-Disposition", "inline;filename=\""+upload.getFileName()+"\"");
try{
BufferedReader bufferedReader = new BufferedReader(new FileReader(upload.getLocalFilePath()));
String line;
PrintWriter out = resp.getWriter();
while ((line = bufferedReader.readLine()) != null)
{
out.println(line);
}
bufferedReader.close();
}
catch(Exception e){
}
I also tried this but get the same result:
//InputStream isStream = null;
//ServletOutputStream sosStream = null;
// try
// {
// //response.flushBuffer();
//isStream = new FileInputStream(new File(upload.getLocalFilePath()));
//sosStream = resp.getOutputStream();
//int ibit = 256;
// while ((ibit) >= 0)
// {
// ibit = isStream.read();
// sosStream.write(ibit);
// }
//
//}
//catch (IOException ioeException)
//{
// }
// sosStream.flush();
// sosStream.close();
// isStream.close();
any help would be greatly appreciated.
Richard