File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes FileNotFound exception when using URLConnection.getInputStream() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "FileNotFound exception when using URLConnection.getInputStream()" Watch "FileNotFound exception when using URLConnection.getInputStream()" New topic

FileNotFound exception when using URLConnection.getInputStream()

Gregory, Banks

Joined: Aug 23, 2001
Posts: 1
I have been working on a client reservation database that uses URL to talk to scripts that do the reading and writing for the applet on the server side. Here is a sample of the offending code:
URL test = new URL(CGI_READ_TEST);
display.append("I have passed cgi test.\n");
URLConnection connection = test.openConnection();

PrintWriter out = new PrintWriter(connection.getOutputStream());

BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine = in.readLine();

//If the script says halt then exit
if(inputLine.compareTo("halt") == 0)
display.append("Someone else is currently using the system.\nPlease try later.");
//--> write exit method
I know the file exists and I know that the url located in final String CGI_READ_TEST is correct. However, I keep getting this error. Does anyone have any suggestions for me?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

System.out.println("The URL IS: \"" + test.toString() + "\"");
And see what it actually THINKS you're trying to open.

An IDE is no substitute for an Intelligent Developer.
Gregory Banks

Joined: Aug 23, 2001
Posts: 5

I tried URL.toString() and it displayed the correct url. I also played around with it a bit and found that if I just commented out the whole part dealing with the URLConnection to the script file (see the code above) and tried to open a URLConnection to a text file, where all my data is stored, in the same directory as the script, it had no complaints and could read the information from that file fine. The text file and the script file have the same permissions and the script file works from the cammand line perfectly. How is it that it can see the text file and not the script file? Any suggestions to correct this would help a great deal.
Roby Saunders

Joined: Aug 04, 2003
Posts: 1
I have also encounterd this error.
Was there any resolution or cause identified?
I agree. Here's the link:
subject: FileNotFound exception when using URLConnection.getInputStream()
It's not a secret anymore!