Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileNotFound exception when using URLConnection.getInputStream()

 
Gregory, Banks
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try:
System.out.println("The URL IS: \"" + test.toString() + "\"");
And see what it actually THINKS you're trying to open.
 
Gregory Banks
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have also encounterd this error.
Was there any resolution or cause identified?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic