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();
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(".");

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

Good luck
更多精彩文章及讨论,请光临枫下论坛. 网址: rolia.net/zh
2001-8-21 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: 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 !

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论