我想知道如何获取项目中的文件的绝对路径,而不是在运行的应用程序中。
例如这一个:
C:\Users\Mr\Documents\Example\org.xtext.example.mydsl\src\example.txt
我尝试过像:
这样的路径val file = new File("relative path");
val absolutePathString = file.getAbsolutePath();
或
System.getProperty("user.dir");
但是他们都检索了Eclipse的路径,而不是我项目的路径。
感谢您的帮助!
答案 0 :(得分:0)
不需要文件。假设你有一个默认的eclipse与默认文件系统,并谈论项目中的文件,你可以看看这些
public void doit(Resource r) {
URI uri = r.getURI();
if (uri.isPlatformResource()) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)));
file.getLocation();
file.getLocationURI();
file.getRawLocation();
file.getRawLocationURI();
}
}