wood burning stoves 2.0*
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "FileNotFound exception when using URLConnection.getInputStream()" Watch "FileNotFound exception when using URLConnection.getInputStream()" New topic
Author

FileNotFound exception when using URLConnection.getInputStream()

Gregory, Banks
Greenhorn

Joined: Aug 23, 2001
Posts: 1
Hello,
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();
connection.setDoOutput(true);

PrintWriter out = new PrintWriter(connection.getOutputStream());
out.println("checkFile");
out.close();

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
return;
}
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?
Cheers,
Greg
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

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


Customer surveys are for companies who didn't pay proper attention to begin with.
Gregory Banks
Greenhorn

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.
Cheers,
Greg
Roby Saunders
Greenhorn

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: http://aspose.com/file-tools
 
subject: FileNotFound exception when using URLConnection.getInputStream()