目录结构:
project
out
src
read.java
test.txt
files
opts
项目为priject
out目录为.class输出目录
src下为文件目录
src下有两个包,files、opts
我想通过相对路径获取test.txt的路径
但是用反射只能获取到.class,也就是out里的路径
//取得根目录路径
String rootPath = getClass().getResource("/").getFile().toString();
//当前目录路径
String currentPath1 = getClass().getResource(".").getFile().toString();
//当前目录的上级目录路径
String parentPath = getClass().getResource("../").getFile().toString();
如何能获取到src下包的相对路径?
MMMHUHU
蓝山帝景
森林海
一只萌萌小番薯
随时随地看视频慕课网APP
相关分类