Path Xtext项目上的绝对路径

Path Xtext项目上的绝对路径,path,xtext,absolute-path,xtend,Path,Xtext,Absolute Path,Xtend,我想知道如何获得文件的绝对路径,该文件在我的项目中,而不是在运行的应用程序中 例如,这个: C:\Users\Mr\Documents\Example\org.xtext.example.mydsl\src\example.txt 我尝试过以下路径: val file = new File("relative path"); val absolutePathString = file.getAbsolutePath(); 或 但它们都检索Eclipse的路径,而不是项目的路径 谢谢你的帮助

我想知道如何获得文件的绝对路径,该文件在我的项目中,而不是在运行的应用程序中

例如,这个:

C:\Users\Mr\Documents\Example\org.xtext.example.mydsl\src\example.txt
我尝试过以下路径:

val file = new File("relative path");
val absolutePathString = file.getAbsolutePath();

但它们都检索Eclipse的路径,而不是项目的路径


谢谢你的帮助

不需要有文件。假设您有一个带有默认文件系统的默认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();

    }
}

你在月食里面吗?您处于独立模式吗?谢谢!但这不是我想要的。假设我有一个默认的Xtext项目,它识别Hello name!。在运行应用程序之前,我想在项目中加载ServiSegGenerator.xtend上的.txt文件或项目中的.java类。我想把这个文件放在src/folder上,但我无法得到那个路径,因为我总是从运行的应用程序中得到C:\eclipse或路径。再次感谢您的时间^^^好吧,但这是一个class.getResource/class.getResourceAsStream UseCase,您指的是哪个项目?如果您在独立模式下调用生成器该怎么办!我已经使用class.getResourceAsStream解决了这个问题,然后在加载的文件上使用了BufferedReader。这样做比试图获取src项目的完整路径更容易。谢谢
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();

    }
}