Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

Reading Properties files in NetBeans

 
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question in multiple forums. It creates duplicate conversations and wastes the time of the people trying to help you.

Thanks,
Dave
 
    Bookmark Topic Watch Topic
  • New Topic