在Eclipse插件中获取当前文件的完整路径 - 找不到FileEditorInput

时间:2015-12-15 11:52:21

标签: java eclipse eclipse-plugin eclipse-rcp

我正在尝试在Eclipse中获取当前打开文件的路径。

我尝试使用这部分代码:

import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.part.FileEditorInput;
import org.osgi.framework.Bundle;

IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IEditorPart editor = page.getActiveEditor();
IEditorInput input = editor.getEditorInput();
IPath path = ((FileEditorInput)input).getPath();

但问题是我收到了编译错误

FileEditorInput cannot be resolved to a type

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

Finalmente ce l' ho fatta。

ecco il codice funzionante:

import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorInput;
import org.osgi.framework.Bundle;


IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IEditorPart editor = page.getActiveEditor();
IEditorInput input = editor.getEditorInput();
IPath path = ((IFileEditorInput)input).getFile().getFullPath();
File myFile = path.toFile();