java177-获取应用程序的路径


import javax.tools.Tool;
import java.net.URLDecoder;
 
//获取类路径
public  final class test132 {
    public static String getClassPath(){
        String path=test132.class.getClassLoader().getResource( "" ).getPath().toString();
        try {
            return URLDecoder.decode( path,"UTF-8" );
        }catch (Exception e){
            e.printStackTrace();
        }
        return path;
    }
}
上面编写方法

定义一个实现类

import javax.tools.Tool;
//获取文件程序类的路径
public class test133 {
    public static void main(String[] args){
        String classPath=test132.getClassPath();
        System.out.println( classPath );
    }
}
运行结果

 

posted @ 2022-07-05 18:42  前端导师歌谣  阅读(50)  评论(0)    收藏  举报