這是我做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信息
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", " ");
}
* 獲得物理路徑,並對路徑中包括的空格進行處理
*
* @param url
* URL地址
* @return 物理路徑
*/
public static String getRealPath(URL url) {
String realPath = url.getFile();
realPath = realPath.replaceFirst("/", "");
// 如果URL地址中含有空格,則空格會被"%20"替換,所以要將它替換回來
realPath = realPath.replaceAll("%20", " ");
}