How to load files using relative path in NetBeans

22,309

In Netbeans you need to put that file inside the project folder rather than in the src/package folder.

Share:
22,309
Raghavendra
Author by

Raghavendra

Functional Programming Enthisiast.

Updated on April 24, 2020

Comments

  • Raghavendra
    Raghavendra about 4 years
    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);
        }
    }
    

    Though the file DBDriverInfo.properties file is in the same directory, the following exception is raised.

    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 paths work fine when compiled using javac in a command line interface. But the exception raises in NetBeans.