use*_*204 4 eclipse workspace file
我正在做一些序列化,它还包含一个需要存储为字符串的IFile路径.
我在一个插件项目中使用这个IFile.为了调试或运行Eclipse,启动一个新工作区.此测试工作空间的根目录相对于插件文件夹.我的问题是,当我将我的IFile转换为绝对路径时,我的Eclipse测试工作空间将该文件视为工作区外部并抛出异常.如果我使用项目相对路径,则从字符串创建IFile失败并且IFile为null.
我真的想要相信它的工作方式我需要它,但我真的很想看到它.有没有办法从项目相对路径重建有效的IFile?
目前,我正在从String-> IFile进行重建,如下所示:
//name is a string with the absolute path
IPath location = new Path(name);
IFile file = project.getFile(location.lastSegment());
Run Code Online (Sandbox Code Playgroud)
但是,就像已经提到的那样,只能使用绝对路径,这在eclipse测试工作空间中不起作用.
谢谢你的提示
你很近.你要:
IPath path = new Path(name);
IFile file = project.getFile(path);
Run Code Online (Sandbox Code Playgroud)
名称应该是绝对(到工作空间)或项目相对路径.此接口在IContainer.getFile(IPath)中定义.我将变量从"位置"更改,因为位置通常表示实际(本地)OS文件路径.要获得路径使用:
IPath path = file.getProjectRelativePath();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5428 次 |
最近记录: |