Loading Java properties file inside EJB

In the J2EE application you can trust the class loader to find the properties file under this directory. For this you should code your application as:

String propFile = "propConfig.properties";
URL url = Thread.currentThread().getContextClassLoader().getResource(propFile);
Properties prop = new Properties();
prop.load( url.openStream() );


or

Properties prop = new Properties();
try
{
prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("hello.properties"));
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}

0 ความคิดเห็น:

แสดงความคิดเห็น

top