Announcement

Collapse
No announcement yet.

Testen ob ein HTML-Document existiert

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Testen ob ein HTML-Document existiert

    Hi!

    Ich würde gern testen ob ein HTML-Document existiert oder nicht.

    Ich hab versucht ein File Objekt zu erstellen und das .html Document direkt dem Konstruktor zu übergeben

    File fil = new File("http://..../index.html");

    Aber bei der anschließenden Abfrage

    if(fil.exists())

    erhalte ich immer das Ergebnis false, obwohl das Document existiert!

    Hat jemand ein Idee, wie ich das Problem lösen könnte?

  • #2
    Da das Objekt File für Files im Dateisystem zuständig ist.

    Siehe Doku:

    --><pre>
    An abstract representation of file and directory pathnames.

    User interfaces and operating systems use system-dependent pathname strings to name files and directories. This class presents an abstract, system-independent view of hierarchical pathnames. An abstract pathname has two components:

    1. An optional system-dependent prefix string,
    such as a disk-drive specifier, "/" for the UNIX root directory, or "\\" for a Win32 UNC pathname, and
    2. A sequence of zero or more string names.

    Each name in an abstract pathname except for the last denotes a directory; the last name may denote either a directory or a file. The empty abstract pathname has no prefix and an empty name sequence.

    -->
    public File(String pathname)

    Creates a new File instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then the result is the empty abstract pathname.

    Parameters:
    pathname - A pathname stringThrows:
    NullPointerException - If the pathname argument is null

    </pre>

    Für so einen Fall würde ich also ein HttpURLConnection Objekt vorschlagen und dann den Status der Verbindung abfragen.

    --> 200 File exisitert
    --> 403 File existiert nicht

    Gruß Dietma

    Comment

    Working...
    X