这是我做License管理遇到的问题,有的是我以前没遇到过的,在这里总结出来,希望对自己和看到的这个日志的各位有所帮助
1。 //获得一个工程里的一个文件的绝对路径
String path = UtilsLicense.class.getClassLoader().getResource("license.xml").getFile();
2。//把工程打成jar包后,解析一个jar包里的一个文件
InputStream license_propertiesInputStream=LicenseView.class.getClassLoader().getResourceAsStream("license.properties");
3。//把工程打成jar包后,获得与jar包同级的一个文件的绝对路径
//获得jar包的路径
String path1=System.getProperty("user.dir") ;
String path= System.getProperty("user.dir") + File.separatorChar + "license.xml";
4。//把工程打成jar包后,解析包里的.properties文件 ,比如国际化时有一个类:LicenseView,它的中文国际化配置文件是:LicenseView_zh_CN.properties
Local locale = new Locale("zh","CN");
ResourceBundle resourceBundle=ResourceBundle.getBundle(LicenseView.Class.getSimpleName(),locale);//如果是英文,那么Local对象就是:en_US
String value = resourceBundle.getString(key);//如果License_zh_CN.properties中有jpnlLicense.border.title=服务端License信息,key为
“jpnlLicense.border.title”,则value为服务端License信息
String path = UtilsLicense.class.getClassLoader().getResource("license.xml").getFile();
2。//把工程打成jar包后,解析一个jar包里的一个文件
InputStream license_propertiesInputStream=LicenseView.class.getClassLoader().getResourceAsStream("license.properties");
3。//把工程打成jar包后,获得与jar包同级的一个文件的绝对路径
//获得jar包的路径
String path1=System.getProperty("user.dir") ;
String path= System.getProperty("user.dir") + File.separatorChar + "license.xml";
4。//把工程打成jar包后,解析包里的.properties文件 ,比如国际化时有一个类:LicenseView,它的中文国际化配置文件是:LicenseView_zh_CN.properties
Local locale = new Locale("zh","CN");
ResourceBundle resourceBundle=ResourceBundle.getBundle(LicenseView.Class.getSimpleName(),locale);//如果是英文,那么Local对象就是:en_US
String value = resourceBundle.getString(key);//如果License_zh_CN.properties中有jpnlLicense.border.title=服务端License信息,key为
“jpnlLicense.border.title”,则value为服务端License信息
5。//获得工程里的一个Properties文件的键值
Properties pro=new Properties() ;
pro.load(inputStream);
pro.getProperty(key);
6。
/**
* 获得物理路径,并对路径中包括的空格进行处理
*
* @param realPath
* 物理路径
* @return 物理路径
*/
public static String getRealPath(String realPath) {
// 如果URL地址中含有空格,则空格会被"%20"替换,所以要将它替换回来
realPath = realPath.replaceAll("%20", " ");
Properties pro=new Properties() ;
pro.load(inputStream);
pro.getProperty(key);
6。
/**
* 获得物理路径,并对路径中包括的空格进行处理
*
* @param realPath
* 物理路径
* @return 物理路径
*/
public static String getRealPath(String realPath) {
// 如果URL地址中含有空格,则空格会被"%20"替换,所以要将它替换回来
realPath = realPath.replaceAll("%20", " ");
return realPath;
}
}
/**
* 获得物理路径,并对路径中包括的空格进行处理
*
* @param url
* URL地址
* @return 物理路径
*/
public static String getRealPath(URL url) {
String realPath = url.getFile();
realPath = realPath.replaceFirst("/", "");
// 如果URL地址中含有空格,则空格会被"%20"替换,所以要将它替换回来
realPath = realPath.replaceAll("%20", " ");
* 获得物理路径,并对路径中包括的空格进行处理
*
* @param url
* URL地址
* @return 物理路径
*/
public static String getRealPath(URL url) {
String realPath = url.getFile();
realPath = realPath.replaceFirst("/", "");
// 如果URL地址中含有空格,则空格会被"%20"替换,所以要将它替换回来
realPath = realPath.replaceAll("%20", " ");
return realPath;
}
}