user2655318
user2655318

Reputation: 67

File not found text.properties in java

I have created an app in which all labels are fetched from a file called text.properties, it is running fine in my IDE, but when i run the jar file using command prompt, the error below is raised.

Oct 04, 2013 9:28:14 AM Main.LoginFrame <init>
SEVERE: null
java.io.FileNotFoundException: text.properties (The system cannot find the file
specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at GraphicUserInterface.LoginFrameGUI.initializingLoginElements(LoginFra
meGUI.java:30)
    at Main.LoginFrame.<init>(LoginFrame.java:72)
    at Main.Main.main(Main.java:41)

Exception in thread "main" java.lang.NullPointerException
    at Main.LoginFrame.<init>(LoginFrame.java:81)
    at Main.Main.main(Main.java:41)

The sample piece of code that calls this properties file is as given below

Properties prop=new Properties();
prop.load(new FileInputStream("text.properties"));
logFrame.usernamelbl = new JLabel(prop.getProperty("lusernamelbl"));

The same approach has worked for me in the past. I have copied the properties type into the netbeans project folder. Please help me to find a solution for this.

Upvotes: 0

Views: 261

Answers (2)

user2655318
user2655318

Reputation: 67

I solved the problem. You just have to copy your properties file to the location where the jar file is present.

Upvotes: 0

Rahul
Rahul

Reputation: 45060

You can to either set the classpath in your command prompt or give the absolute path of your properties file for it to work.

prop.load(new FileInputStream("full/path/where/the/file/is/text.properties"));

Upvotes: 1

Related Questions