0
给定一个文件资源,我想知道它的内容类型是否基于文本,即不是二进制文件。如何确定文件是否是Eclipse中的文本文件
IFile file = ...
IContentType contentType = IDE.getContentType(file);
boolean textBased = ...
给定一个文件资源,我想知道它的内容类型是否基于文本,即不是二进制文件。如何确定文件是否是Eclipse中的文本文件
IFile file = ...
IContentType contentType = IDE.getContentType(file);
boolean textBased = ...
有一个预定义的文本内容类型,可以通过IContentTypeManager.CT_TEXT
常量获得。所有内容类型都是这种内容类型是这是一种基于文本的内容类型。
IFile file = ...
IContentType contentType = IDE.getContentType(file);
IContentType textContentType = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT);
boolean textBased = contentType.isKindOf(textContentType);
另外的ITextFileBufferManager
可以确定如果路径指向一个文本文件中。
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
boolean textBased = manager.isTextFileLocation("/path/to/file", false);
该位置可以是工作区资源的完整路径或本地文件系统中的绝对路径。第二个参数确定是否应将具有未知内容类型的文件视为文本文件(true
)或不包含(false
)。