Hi,
I am trying to retrieve an image file from the ASP.
The program is throwing an error saying -
Exception in thread "main" java.io.FileNotFoundException: http://host/ImageProcess/Image.asp
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:560)
at java.net.URLConnection.getContent(URLConnection.java:565)
at test.TestASP.main(TestASP.java:28)
It works most of the times and it throws the above message once in a while. Is there a work around for this? Is there anything wrong in the code?
Here is the test Java program -
public class TestASP
{
public static void main(String[] args) throws Exception
{
String urlString = args[0];
String aspData = "intPageNumber=0^isLog=Y\r\nF_DOCNUMBER = " + args[1];
URL url = new URL(urlString);
URLConnection urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
DataOutputStream toAsp = new DataOutputStream(urlConn.getOutputStream());
toAsp.write(aspData.getBytes(), 0, aspData.length());
toAsp.close();
urlConn.connect();
InputStream fromAsp = (InputStream) urlConn.getContent();
String errorMessage = urlConn.getHeaderField("errorMessage");
if (errorMessage != null)
{
throw new Exception(errorMessage);
}
String fileLength = urlConn.getHeaderField("fileLength");
if (fileLength == null)
{
throw new Exception("File length is null");
}
FileOutputStream imageFile = new FileOutputStream(args[2]);
byte buff[] = new byte[4096];
int len = 0;
while ((len = fromAsp.read(buff)) > 0)
{
imageFile.write(buff, 0, len);
}
imageFile.close();
fromAsp.close();
}
}
Thanks
Satish
Discussions
Web tier: servlets, JSP, Web frameworks: help to resolve FileNotFoundException in getContect()
-
help to resolve FileNotFoundException in getContect() (0 messages)
- Posted by: Satish Babu
- Posted on: March 14 2003 14:50 EST