2010-06-16 57 views
0

ABS路徑我有同樣的問題,因爲在這個崗位的傢伙: Get the absolute path of the currently edited file in Eclipse獲取從當前編輯的文件在Eclipse

,但我不知道如何做到這一點。在帖子中,他們說我應該使用IResource.getRawLocation(),但是如何從當前正在查看的文件中獲取IResource?

IFile file2 = (IFile)workBench.getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput().getAdapter(IFile.class); 

IPath path = file2.getRawLocation().makeAbsolute(); 
String ss = path.toString(); 

System.out.println(ss); 

但這仍然不會給我鏈接文件中的正確的道路,我得到的是這樣的: /路徑/到/插件/路徑/到/相對/路徑/到/文件

回答

0

IFile是一個IResource。你不需要從另一個獲得一個。請致電file2.getRawLocation()。如果這不起作用,這不是因爲它不是IResource。

該文件是否在jar/zip /任何存檔文件中?如果是這樣,它看起來可能是正確的絕對路徑。

+0

我認爲它的工作:) – hidayat 2010-06-16 14:47:09

相關問題