我想以编程方式获取 Eclipse 中打开的所有文件的元数据(创建时间、上次修改时间、大小等)。
我有代码可以在 Eclipse 编辑器中打开文件列表,我想知道是否可以获取每个文件的元数据。
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorReference [] editors = page.getEditorReferences();
最佳答案
你可以尝试下面的代码,下面我为你提供了伪代码。
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorReference [] editors = page.getEditorReferences();
for (IEditorReference editorReference : editors) {
try {
IEditorInput editorInput = editorReference.getEditorInput();
if (editorInput instanceof IFileEditorInput) {
IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
IFile file = fileEditorInput.getFile();
//Once you get the file, convert it into java.io.File and you can get all the metadata from file
//Write your own logic to print and to check
}
} catch (PartInitException e) {
e.printStackTrace();
}
}
关于java - 如何以编程方式获取在 Eclipse 中打开的文件的元数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56226186/