2016-03-15 93 views

回答

1

有一个预定义的文本内容类型,可以通过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)。

相关问题