• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FileNotFound exception when using URLConnection.getInputStream()

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have also encounterd this error.
Was there any resolution or cause identified?
 
reply
    Bookmark Topic Watch Topic
  • New Topic