如何在Eclipse工作区中获取活动包路径 [英] How to get the active package path in eclipse workspace
问题描述
我不确定这是否是正确的问题,因为我无法获取我在eclipse中选择的文件夹的绝对路径。
Im not sure whether it is the right question because i m not able to get the absolute path of the folder which i have selected in eclipse.
以下是我写的代码,谁能告诉我缺少了什么?
The following is the code i wrote , can anyone tell me what is missing ?
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null)
{
IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();
Object firstElement = selection.getFirstElement();
if (firstElement instanceof IAdaptable)
{
IFolder folder = (IFolder)((IAdaptable)firstElement).getAdapter(IFolder.class);
IPath path = folder.getLocation();
System.out.println(path);
}
}
提前谢谢!!!
推荐答案
尝试使用
因此,在您的示例中,您可以编写:
Try to make your path
to an absolute path using IPath#makeAbsolute(). You can also transform it to an File using IPath#toFile() and then make it absolute (File#getAbsolutePath()).
So in your sample you could write:
IPath path = folder.getLocation();
System.out.println("Absolute Path: "+path.makeAbsolute());
System.out.println("Absolute FilePath: "+path.toFile().getAbsolutePath());
这篇关于如何在Eclipse工作区中获取活动包路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!