Bookmark Topic Watch Topic
  • New Topic

NetBeans Problem While Reading properties files  RSS feed

 
bugrip ark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi

I'm facing problem while reading properties file with java program in NETBEANS IDE.The same Program is working fine in ECLIPSE IDE.How can i run this program correctly in NetBeans please help me out.The Program is give below (all files are in "propdemo" package)
----------------------------------------------------
package propdemo;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class MyProp {

private static Properties prop =null;
public static Properties loadProperties(){
InputStream in=null;
try{
if(prop==null)
{
ClassLoader cl=ClassLoader.getSystemClassLoader();
in=cl.getResourceAsStream("propdemo/prop.properties");
prop = new Properties();
prop.load(in);
}
}catch(IOException ioe){
ioe.printStackTrace();
}
return prop;
}

}
--------------------------------------------

package propdemo;

import java.util.Properties;

public class RunMe {
/**
* @param args
*/
public static void main(String[] args) {

Properties pr = MyProp.loadProperties();
System.out.println(pr.getProperty("prop2"));

}

}
---------------------------------------------------------------
& prop.properties files content

prop1=This is property 1
prop2=This is property 2
prop3=This is property 3
prop4=This is property 4
prop5=This is property 5



Thanks
bbtrip
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post the same question in multiple forums. It causes confusion and duplication of effort as the community tries to help everyone.
Also, you must have missed our naming policy on the way in. In short, we ask that you use a first and last name, separated by a space and not obviously fake. You can change your name here.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!