Locate the path to the resource file in Java

xiaoxiao2021-03-06  76

Recently, because of writing a thing, save the configuration in XML, how can I find XML? Is a problem?

I saw JWHICH and wrote a small function of looking for a resource file path. (I don't know if it is right, if there is wrong, please point out)

/ **

* If you can't find it, return NULL.

* @Param SResourceName

* @Return

* /

Public Static String getResourceFilePath (String SResourceName)

{

IF (! SResourceName.startSwith ("/"))

{

SResourceName = "/" SResourceName;

}

Java.net.url ClassURL = jwhichutil.class.getResource (SResourceName);

IF (ClassURL == Null)

{

System.out.println ("/ NResource '" SResourceName "NOT Found In / N'"

System.getProperty ("java.class.path") "'");

Return NULL;

}

Else

{

System.out.println ("/ NResource '" SResourceName "' Found In / N '" ClassURL.GetFile () "');

Return Classurl.getFile ();

}

}

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

New Post(0)