我在看代码new FileInputStream("config.properties")。
我在我的项目中的多个地方都有相同的文件"config.properties“(执行windows文件搜索),现在我很困惑这个函数调用所引用的是哪一个。如何了解文件的绝对路径?
我在网上发现了这个,但是这个位置看起来不太合适。
"ClassName".class.getProtectionDomain().getCodeSource().getLocation().getPath(),但这看起来不像。如果我错了,你能纠正一下吗?
发布于 2013-04-11 15:25:05
您可以使用File
File f = new File("config.properties");
System.out.println(f.getAbsolutePath());返回的路径将从当前工作目录中推导出来。
发布于 2013-04-11 15:26:03
File f = new File("config.properties");
String dirPath = file.getParentFile().getAbsolutePath()https://stackoverflow.com/questions/15952711
复制相似问题