public abstract class FileTypeDetector extends Object
一个文件类型检测器是这个类的一个具体实现,有一零个参数构造函数,并实现了下面指定的抽象方法。
文件类型检测器确定文件类型的方法是高度实现特定的。一个简单的实现可能检查文件扩展(在某些平台上使用的一个约定),并将其映射到文件类型。在其他情况下,文件类型可以存储为一个文件或文件中的字节 attribute可检查猜测其文件类型。
Files.probeContentType(Path)
Modifier | Constructor and Description |
---|---|
protected |
FileTypeDetector()
初始化该类的一个新实例。
|
protected FileTypeDetector()
SecurityException
如果安全管理器已经安装,它否认
RuntimePermission
("fileTypeDetector")
public abstract String probeContentType(Path path) throws IOException
该方法确定文件类型的方法是高度实现特定的。它会检查文件名,它可以使用一个文件attribute,或者可以检查文件中的字节。
调查的结果是一个多用途的值的字符串形式(MIME)内容类型所定义的RFC 2045: Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies。字符串必须解析根据RFC 2045语法。
path
-文件的路径探讨
null
如果文件类型无法识别
IOException
- I/O错误发生
SecurityException
如果执行需要访问的文件,以及安全管理器安装,它否定了未经文件系统供应商实施要求。如果文件是默认的文件系统提供商,然后
SecurityManager.checkRead(String)
方法被调用来检查对文件的读访问相关。
Files.probeContentType(java.nio.file.Path)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.