package pdfservice;
import java.io.FileInputStream;
import java.net.URLDecoder;
import java.util.Properties;
/**
* 获取jdbc.properties配置文件的信息
*/
public class PdfConfig {
private static Properties PROP = new Properties();
private static String ENCODING = "utf-8";
static{
try {
String path = URLDecoder.decode(PdfConfig.class.getResource("jdbc.properties").getFile(),"UTF-8");
PROP.load(new FileInputStream(path));
if(PROP.containsKey("encoding")){
ENCODING = PROP.getProperty("encoding");
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 根据KEY获取值
* @param key
* @return
*/
public static String get(String key){
try {
String value = PROP.getProperty(key);
if(value!=null){
value = new String(value.getBytes("iso-8859-1"),ENCODING);
}
return value;
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
public static void main(String[] args) {
//调用示例
String name = PdfConfig.get("jdbc.name");
System.out.println(name);
}
}
获取properties配置文件
最新推荐文章于 2024-05-24 10:49:58 发布