属性管理器. Java
import java.io.*;
import java.util.Properties;
//*
公共类属性管理器{
//配置文件路径
privatestaticfinalstringconfig _ file _ name=' config.properties ';
//内存中的配置
privatestaticpropertiesprops=new properties (;
静态{
try {
//初始化
inputstream=properties manager.class.getclass loader (.getresourceasstream (config _ file _ name ) );
props.load(Inputstream );
}catch(ioexceptione ) {
e .打印任务跟踪(;
} finally {
try {
输入流!=null ) {
inputStream.close (;
}
}catch(exceptione ) {
}
}
}
私有属性管理器
}
publicstaticstringgetproperty (string key ) (
returnprops.getproperty(key;
}
publicstaticvoidsetproperty (string key,String value )。
try {
//获取输出流
output stream=new file output stream (properties manager.class.getclass loader ).getresource ) config_file_name )。
//设置属性
props.setproperty(key,value );
//存储
props.store(outputstream,null );
}catch(exceptione ) {
e .打印任务跟踪(;
}finally {
try {
输出流!=null ) {
outputStream.close (;
}
}catch(exceptione ) {
}
}
}
}
版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。