A relative path to the current file in the class and the absolute path

xiaoxiao2021-03-06  42

Package IO;

Import java.net.URL;

/ **

*

Title: The relative path where the current file is located and the absolute path is located

*

*

Description: The relative path where the current file is located in the class and the absolute path

*

*

Copyright: Copyright (c) 1997 - 2005

*

*

Company: beyond daybreak office

*

* @AuThor Yulimin

* @version 1.0

* /

Public Class getClassPath

{

Public getClassPath ()

{

Super ();

}

/ **

* main

*

* @Param args string []

* /

Public static void main (string [] args)

{

GetClassPath getClassPath = new getclasspath ();

System.out.println (GetClassPath.getClassPath ());

}

/ **

* The relative path to the current file is located in the class and the absolute path

*

* @Return String

* /

Public string getclasspath ()

{

String strclassname = getclass (). Getname ();

String strpackagename = ""

IF (getClass (). getpackage ()! = null)

{

StrPackageName = getClass (). getName (); GetName ();

}

System.out.println ("ClassName: StrClassName);

System.out.println ("PackageName: StrPackageName);

String strclassFilename = "";

IF (! ". Equals (strpackagename))

{

STRCLASSFILENAME = STRCLASSNAME.SUBSTRING (STRPACKENAME.LENGTH () 1, STRCLASSNAME.LENGTH ());

}

Else

{

STRCLASSFILENAME = STRCLASSNAME;

}

System.out.println ("ClassFileName:" STRCLASSFILENAME);

URL URL = NULL;

URL = getClass (). getresource (strclassfilename ".class");

Strincel = url.tostring ();

Strurl = Strurl.substring (Strull.IndexOf ('/') 1, Strurl.lastIndexOf ('/'));

Return Strurl;

}

}

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

New Post(0)