So laden Sie Dateien mit relativem Pfad in NetBeans

import java.io.*;
import java.util.Properties;

public class NewClass {
    public static void main(String args[]) throws IOException  {
        Properties p = new Properties();
        p.load(new FileInputStream("DBDriverInfo.properties"));
        String url=p.getProperty("url");
        String user=p.getProperty("username");
        String pass=p.getProperty("password");
        System.out.println(url+"\n"+user+"\n"+pass);
    }
}

Obwohl die Datei DBDriverInfo.properties Datei ist im selben Verzeichnis, wird die folgende Ausnahme ausgelöst.

Exception in thread "main" java.io.FileNotFoundException: DBDriverInfo.properties (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at java.io.FileInputStream.<init>(FileInputStream.java:97)
    at NewClass.main(NewClass.java:7)

Relative Pfade funktionieren, wenn kompiliert mit javac in ein command line interface.
Aber die Ausnahme wird ausgelöst, in NetBeans.

InformationsquelleAutor Raghavendra | 2012-08-24

Schreibe einen Kommentar