栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JAVA IO - 获取类路径

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAVA IO - 获取类路径

1.什么是类路径
1.类路径 就是告诉JVM虚拟机从哪里去寻找要执行的类;
(通俗的理解:就是存放class文件的目录)
2.如果不指定,则默认在 java 命令执行的目录下进行寻找。
2.获取类路径的三种方式 2.1 代码
package com.northcastle.file;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


public class ApplicationFilePath {
    public static void main(String[] args) throws IOException {

        
        String classPath01 = ApplicationFilePath.class.getClassLoader().getResource("").getPath();
        System.out.println("classPath01 == "+classPath01);

        String classPath02 = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        System.out.println("classPath02 == "+classPath02);

        String classPath03 = ApplicationFilePath.class.getResource("/").getPath();
        System.out.println("classPath03 == "+classPath03);

    }


}

2.2 执行结果

直接指向了编译后的class文件的目录


3.完成

Congratulations!
You are one step closer to success!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/727548.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号