If a class needs a .properties file or .xml file, I usually use Java resource mechanism.....

jabber (jabber)
本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
Let me say we have a com.abccompany.infrastructure.DBConnection class. Right beside this class, we can create dbconfiguartion.properties file. Then in the constructor, we may read properties file as follows

Class cls = this.getClass();
ClassLoader loader = cls.getClassLoader();
InputStream input = loader.getResourseAsInputStream("com/abccompany/infrastructure/dbconfiguration.properties");
Properties p = new Properties();
p.load(input);
.................................
The above code may contain mistakes but the main idea is correct.
Configuartion properties file is part of the class file, so it is always shipped with the class file. Never separate it from the class file.

If you are talking about server configuartion, please follow server documentation.

Each server has its different "." direcetory. You can create a small Java servlet programm to determine it:
.....................
File file =new File(".");
System.out.println(file.getAbstractPath());
........

The above code should be in a doGet, doPost or service method.

Good luck
更多精彩文章及讨论,请光临枫下论坛. 网址: rolia.net/zh
(#174572@0)
2001-8-21 -05:00

回到话题: Jabber: When you are writing a java program, you surely will take care of the configuration file , right ? what method do u use to read and write the configuration file ??!! Thank you in advance !

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论

URL:   
http://www.rolia.net/zh/post.php?f=0&p=174572