aspose file tools
The moose likes Java in General and the fly likes Reading Properties files in NetBeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Reading Properties files in NetBeans

bugrip ark
Greenhorn

Joined: Feb 22, 2007
Posts: 4
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

Joined: Mar 06, 2001
Posts: 13459

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
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: Reading Properties files in NetBeans