Solved

URL-problems!

Posted on 1997-08-19
2
230 Views
Last Modified: 2012-06-21
Hi,

I'm trying to write a snippet of code, to determine if a URL-documnet
exists, before I use it with the AppletContext.showDocument-method, and
it looks like this:

private boolean fileExist(URL url)
        {
            try {
                InputStream testStream = url.openStream();
                } catch (IOException ioe) {
                    return false;
                }
            return true;
        }

, but it doesn't seem to work!

NetScape's implementation of Java doesn't seems to catch the IOException
at all!

Is there a better way?
0
Comment
Question by:atti
2 Comments
 
LVL 1

Accepted Solution

by:
mnelson051997 earned 50 total points
ID: 1225411
It worked Ok for me in netscape 3.01.  Following is the
full text of the applet that returned false:

import java.io.*;
import java.net.*;
import java.applet.*;

public class Test1 extends Applet
{
   public void init()
   {
      try{

      // Returns false.

      System.out.println( fileExist( new URL( "http://www.zeh.crom" ) ) );

      // Returns true.

      //System.out.println( fileExist( new URL( "http://www.zeh.com" ) ) );
      }catch(Exception e ) { System.out.println( "--"+e ); }
   }

   private static boolean fileExist(URL url)
   {
       try {
       InputStream testStream = url.openStream();
       } catch (IOException ioe) {
       return false;
       }
       return true;
   }
}

Are you running a different version of Netscape?
M
0
 

Author Comment

by:atti
ID: 1225412
Are you running a different version of Netscape?
                                 
Yes, I'm running Netscape 4 and it doesn't work.... :-(
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
unix in java example 9 52
eclipse shortcuts 9 45
servlet requestdispatcher include and forward differences 1 22
Spring Framework HTTPSession management 1 21
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now