1.一个类获取相关路径下其他文件
URL sqlURL = TestProcessController.class.getResource("/controller/testProcess/dropTables.sql");
String sqlPath = java.net.URLDecoder.decode(sqlURL.toString(), "utf-8");
sqlPath = sqlPath.toString().substring(6);
2.获取项目目录下的文件(夹)
String bootPath = System.getProperty("user.dir");
System.out.println("项目根目录为:"+bootPath);
File file = new File(bootPath + File.separator + "examples");
if(file.isDirectory()){
File[] listFiles = file.listFiles();
for (File file2 : listFiles) {
System.out.println(file2.getName());
}
}
打印信息如下:
项目根目录为:D:\workspace\CA
example.go
main.m
pythonTest.py
test.abap
test.cls
test.cs
test.go
test.hs