Re: URL.openStream gives FileNotFoundException

webmasterbeta

New Member
I can even generalize my problem as follows:There seems to be problems to connect to a url on the localhost wheneverthere is a default file or virtual path configured.I use the following code in order to test this:[Start Code]import java.net.*;import java.io.*;public class Connect{static public void main(String [] sa) {if (sa.length != 1) {System.out.println("Usage:");System.out.println(" Connect <url>");System.out.println("Example:");System.out.println(" Connect <!-- m --><a class="postlink" href="http://www.yahoo.com">http://www.yahoo.com</a><!-- m -->");return;}try {URL url = new URL(sa[0]);BufferedReader in = new BufferedReader(newInputStreamReader(url.openStream()));String inputLine;while ((inputLine = in.readLine()) != null)System.out.println(inputLine);in.close();}catch (Exception x) {System.out.println("Exception: ");x.printStackTrace();}}}[End Code]"Connect <!-- m --><a class="postlink" href="http://www.yahoo.com">http://www.yahoo.com</a><!-- m -->" works perfectly.When using "Connect <!-- m --><a class="postlink" href="http://localhost">http://localhost</a><!-- m -->", it gives the following Exception:java.io.FileNotFoundException: <!-- m --><a class="postlink" href="http://localhost/localstart.aspatsun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection..java:545">http://localhost/localstart.aspatsun.ne ... ..java:545</a><!-- m -->)at java.net.URL.openStream(URL.java:798)at Connect.main(Connect.java:9)This sugests that "http://localhost" is correctly getting translated into"http://localhost/localstart.asp", but somehow it stopes when opening thestream.Opening "http://localhost" in my browser works perfectly and opens the IIShomepage in this case (and indeed the url automatically changes into"http://localhost/localstart.asp").I have the same problems when I try to connect to a cgi script or a servleton my localhost.webserver used is IIS (and in the case I try to use servlets I use JRun3.0).
 
Back
Top