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