publicclassgetproperties { privatestaticpropertiesconfig=null; static { inputstream in=get properties.class.getclass loader (.getresourceasstream (' config.properties ' ) ); config=newP .
公共类获取属性{
privatestaticpropertiesconfig=null;
静态{
' config.properties ';
config=new Properties (;
try {
config.load(in;
in.close (;
}catch(ioexceptione ) {
}
}
基于//key读取值
publicstaticstringreadvalue (string key ) {
//properties props=new properties (;
try {
string value=config.getproperty (key;
返回值;
}catch(exceptione ) {
e .打印任务跟踪(;
返回空值;
}
}
读取属性的所有信息
publicstaticvoidreadallproperties {
try {
enumeration en=config.property names (;
while(en.hasmoreelements () ) ) ) )。
stringkey=(string ) en.nextElement );
字符串属性=config.getproperty (key );
}
}catch(exceptione ) {
e .打印任务跟踪(;
}
}
publicstaticvoidmain (string args [ ] ) {
//stringlasaphone=config.getproperty (las aphone );
//system.out.println(lasaphone );
//system.out.println (get phone.read value (' las aphone ' ) );
get properties.read all properties (;
}
}
config.properties文件:
#area message phone :
Java.lang.exceptioninitializererror
caused by : Java.lang.dq dch/pat Java.io.reader.(reader.Java :61 ) )。
at Java.io.input streamreader.(input streamreader.Java :80 )
at Java.util.properties.load (properties.Java :189 )
atcom.liuchen.get properties.(get properties.Java :16 )
Exception in thread 'main '
虽然在src目录中有记载,但还在报告那个错误
这也不行,这是怎么回事?