做License管理的收获

        这是我做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信息
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", " ");
        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", " ");
        return realPath;
    }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值