gpt4 book ai didi

java - 如何使用插件获取eclipse中项目文件的绝对路径

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:10:12 28 4
gpt4 key购买 nike

我正在尝试创建一个插件,它会给我一个在 eclipse 中打开的项目中所有文件的绝对路径列表。

我试过了,但我只能得到 Activity 窗口的路径..

我的操作代码是:

  IWorkbenchPart workbenchPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); 
IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
if (file == null)
try {
throw new FileNotFoundException();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String path = file.getRawLocation().toOSString();
System.out.println("path: " + path);

这里我只获取 Activity 窗口的路径..但​​我想要项目中所有文件的绝对路径列表..主要是 src 文件夹下的文件...

请指导我是否可以用相同的方式来做,或者我是否需要为此使用一些不同的 API。

最佳答案

经过研究,我发现下面的代码可以获取 Eclipse 当前工作区的项目目录的路径:

//get object which represents the workspace  
IWorkspace workspace = ResourcesPlugin.getWorkspace();

//get location of workspace (java.io.File)
File workspaceDirectory = workspace.getRoot().getLocation().toFile()

注意:您需要导入 org.eclipse.core.resourcesorg.eclipse.core.runtime 才能使用这些 API

Source

关于java - 如何使用插件获取eclipse中项目文件的绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15246736/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com