集册 Java实例教程 获取课程目录

获取课程目录

欢马劈雪     最近更新时间:2020-01-02 10:19:05

443
获取课程目录
//时代Java - nowjava.com

//package com.nowjava;

import java.io.File;


import java.net.URL;


public class Main {

    public static void main(String[] argv) throws Exception {

        Class testClass = String.class;

        System.out.println(getClassDirectory(testClass));

    }


    public static String getClassDirectory(Class testClass) {

        String resource = testClass.getSimpleName() + ".class";

        URL ressourceURL = testClass.getResource(resource);

        String absolutPath = ressourceURL.getPath();

        absolutPath = absolutPath.replace('/', File.separatorChar);//来自 时   代     Java  公  众  号 - nowjava.com

        absolutPath = absolutPath.replace('\\', File.separatorChar);

        String className = testClass.getName();

        String classNamePath = className.replace('.',
展开阅读全文