我想从包资源管理器中检索选定的java文件的路径/文件名 [英] I want to retrieve the path/filename of the selected java file from the package explorer
问题描述
我编写的代码成功地检索了xml的文件名/路径或清单文件,但无法检索包中Java文件的路径。
我使用的代码是: -
if(selection instanceof IStructuredSelection)
{
Object o =((IStructuredSelection)selection).getFirstElement();
if(o instanceof IFile)
{
IPath loc =((IFile)o).getLocation();
if(loc!= null)
{
selectedFile = loc.toOSString();
}
else
selectedFile =error at loc;
}
else
selectedFile =O at error
}
感谢GUYZ,使用您的帮助进行图解
解决方案是 -
对象o =((IStructuredSelection)选择) .getFirstElement();
den
IPath loc =((ICompilationUnit)o).getPath();
den
selectedFile = loc.toOSString();
有了这个,你就可以获取您选择的java文件的路径。并且,这显示了从项目名称开始的路径名,有人可以告诉如何获取整个物理路径名,驱动器等。..
I am developing a plugin that requires retrieval of path/filename of java files.
The code that I have written, successfully retrieves the filenames/path of the xml or manifest files, but is unable to retrieve the path of the Java files in the packages.
The code I have used is :-
if (selection instanceof IStructuredSelection)
{
Object o = ((IStructuredSelection) selection).getFirstElement();
if (o instanceof IFile)
{
IPath loc = ((IFile) o).getLocation();
if (loc != null)
{
selectedFile = loc.toOSString();
}
else
selectedFile = "Error at loc";
}
else
selectedFile = "Error at O";
}
THANKS GUYZ, I WAS ABLE TO FIGURE IT OUT WITH YOUR HELP
THE SOLUTION IS -
Object o = ((IStructuredSelection) selection).getFirstElement();
den IPath loc = ((ICompilationUnit) o).getPath();
den selectedFile = loc.toOSString();
With this, you will be able to get the path of the java file that u selected. and also, this shows the pathname starting from the project name, can someone tell how to get the entire physical pathname, with the drives and such as well..??
这篇关于我想从包资源管理器中检索选定的java文件的路径/文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!