zoukankan      html  css  js  c++  java
  • 获取jar包当前的路径

    转自:http://kinganpo.iteye.com/blog/876243

    import java.io.File;  
    /** 
     * 获取打包后jar的路径信息 
     * @author Administrator 
     *  2011-01-16 13:53:12 
     */  
    public class JarTool {  
        //获取jar绝对路径  
        public static String getJarPath(){  
            File file = getFile();  
            if(file==null)return null;  
             return file.getAbsolutePath();  
        }  
        //获取jar目录  
        public static String getJarDir() {  
            File file = getFile();  
            if(file==null)return null;  
             return getFile().getParent();  
        }  
        //获取jar包名  
        public static String getJarName() {  
            File file = getFile();  
            if(file==null)return null;  
            return getFile().getName();  
        }  
      
        private static File getFile() {  
            //关键是这行...  
            String path = JarTool.class.getProtectionDomain().getCodeSource()  
                    .getLocation().getFile();  
            try{  
                path = java.net.URLDecoder.decode(path, "UTF-8");//转换处理中文及空格  
            }catch (java.io.UnsupportedEncodingException e){  
                return null;  
            }  
            return new File(path);  
        }  
          
    } 
    

      

  • 相关阅读:
    LeetCode:33. Search in Rotated Sorted Array
    重拾 ACM-HDU 2000-2009
    hdu 1022 数据结构 stack模拟
    画椭圆
    声控灯
    VC++调用R语言
    Setup Factory打包时注册com dll
    折腾树莓派的一些总结
    老调重弹
    制作cpprefernce.chm
  • 原文地址:https://www.cnblogs.com/endtel/p/9587772.html
Copyright © 2011-2022 走看看