String path = MainTest.class.getResource("").getPath();//得到当前类class的目录
String binPath = MainTest.class.getResource("").getPath();//得到当前类class的目录
String appPath= new File(binPath).getParentFile().getAbsolutePath()//当前的工程目录
本文介绍了一种在Java中获取当前类及工程目录路径的方法,通过使用MainTest类的getResource方法来实现。此方法对于理解Java项目的文件结构及路径获取非常有用。
String path = MainTest.class.getResource("").getPath();//得到当前类class的目录
String binPath = MainTest.class.getResource("").getPath();//得到当前类class的目录
String appPath= new File(binPath).getParentFile().getAbsolutePath()//当前的工程目录
975

被折叠的 条评论
为什么被折叠?