After the program is a JAR package, the method of accessing the path

zhaozj2021-02-17  56

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", SYSTEME 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;}

}

转载请注明原文地址:https://www.9cbs.com/read-30394.html

New Post(0)