zoukankan      html  css  js  c++  java
  • 获取jar绝对路径

    package Io;

    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;

    public class JarToolUtil {
    /**
    * 获取jar绝对路径
    *
    * @return
    */
    public static String getJarPath()
    {
    File file = getFile();
    if (file == null)
    return null;
    return file.getAbsolutePath();
    }

    /**
    * 获取jar目录
    *
    * @return
    */
    public static String getJarDir()
    {
    File file = getFile();
    if (file == null)
    return null;
    return getFile().getParent();
    }

    /**
    * 获取jar包名
    *
    * @return
    */
    public static String getJarName()
    {
    File file = getFile();
    if (file == null)
    return null;
    return getFile().getName();
    }

    /**
    * 获取当前Jar文件
    *
    * @return
    */
    private static File getFile()
    {
    // 关键是这行...
    String path = JarToolUtil.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);
    }

    /**
    * 获取当前目录下的文件
    */
    public static List<String> getFile(String path) {
    File file = new File(path);

    File[] fileList = file.listFiles();
    List<String> list = new ArrayList<String>();
    for (int i = 0; i < fileList.length; i++) {
    if (fileList[i].isFile()) {
    String fileName = fileList[i].getName();
    list.add(fileName);
    }
    /*if (fileList[i].isDirectory()) {
    String fileName = fileList[i].getName();
    System.out.println("目录:" + fileName);
    }*/
    }
    return list;
    }
    }

  • 相关阅读:
    DataTable转换成IList<T>的简单实现
    websocket
    获取用户使用设备信息
    判断对象是否相等
    关于PC适配
    树形数据结构实现平铺展示
    埋点
    多层表单验证
    表格行拖动,数据中状态值不同的禁止拖拽
    element tree 深度查询
  • 原文地址:https://www.cnblogs.com/developer-ios/p/12438635.html
Copyright © 2011-2022 走看看