CSDN博客

img mysine

程序打成Jar包以后,访问路径的方法

发表于2002/11/4 13:05:00  903人阅读

public class Path
{

  private static String homePath;

  public static String getHome()
  {
    String path = System.getProperty("test.home");
    if (path != null) {
      return path;
    }
    String homePath = getProjectPath();
    System.setProperty("test.home",homePath);
    return homePath;
  }

  public static String getClassPath(){
    String path = System.getProperty("test_class.home");
    if (path != null) {
      return path;
    }
    String homePath = new SysConfigPath().getClass().getResource("").getFile();
    String packpath = "aygl_export/";
    int index = homePath.lastIndexOf(packpath);
    homePath = homePath.substring(0, index);
    System.setProperty("test_class.home",homePath);
    return homePath;
  }

  private static String getProjectPath(){
    String homePath = getClassPath();
    int index = homePath.lastIndexOf(".jar!/");

    if (index != -1){
      homePath = homePath.substring(0, homePath.length()-1);
      index = homePath.lastIndexOf("/");
      homePath = homePath.substring(0, index+1);
      homePath = homePath.substring(5);
    }
    homePath = homePath.substring(0, homePath.length()-1);
    index = homePath.lastIndexOf("/");
    homePath = homePath.substring(0, index+1);
    return homePath;
  }

}

0 0

相关博文

我的热门文章

img
取 消
img