我正在尝试在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
我该如何解决这个问题?
答案 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();