• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Streaming PDF, Connecion Error

 
Sipho Motha
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying to write a program that will open PDF file from the browser.
I tells that the Connection refused.
The code is shown below:
The url is = http://localhost/PdfFile.pdf

private void streamCharacterData(String urlstr,String format, PrintWriter outstr, HttpServletResponse resp)
{
String ErrorStr = null;
try{
//find the right MIME type and set it as contenttype
resp.setContentType(getMimeType(format));
InputStream in = null;
try{
URL url= new URL(urlstr);
URLConnection urlc= url.openConnection();
int length = urlc.getContentLength();
in = urlc.getInputStream();
resp.setContentLength(length);
int ch;
while ( (ch = in.read()) != -1 ) {
outstr.print( (char)ch );
}
} catch (Exception e) {
e.printStackTrace();
ErrorStr = "Error Streaming the Data";
outstr.print(ErrorStr);
} finally {
if( in != null ) {
in.close();
}
if( outstr != null ) {
outstr.flush();
outstr.close();
}
}
}
catch(Exception e){
e.printStackTrace();
}
}
can you show me the error
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic