本文发表在 rolia.net 枫下论坛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
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