在Java应用程序中确定文档是DOC还是DOCX而不知道其扩展名
内容管理系统有一个限制,要求存储具有特定扩展名(不同于 DOC 或 DOCX)的所有 Word 文档。然而,当向用户输出文档时,我们需要知道它是 DOC 还是 DOCX 文件,以便提供正确的 MIME 类型。
那么,有没有一种方法可以通过编程方式根据内容确定文档是 DOC 还是 DOCX?
There is a constraint in the content management system that requires to store all word documents with specific extension (different from DOC or DOCX). However, when outputting the document to user we need to know if it is a DOC or DOCX file in order to provide the right MIME type.
So, is there a way to programatically find out if document is DOC or DOCX by its content?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此处是 ForensicsWiki 的链接,其中详细介绍了许多不同的文件类型。它描述了 DOC 和 DOCX 文件的标头,因此您应该能够解析文件并确定它们是什么类型。
查看链接,.doc 文件是 OLE 复合文件,该文件应具有以下二进制标头:
相反,.docx 文件将具有二进制签名:
Here is a link to the ForensicsWiki which details lots of different file types. It describes the headers of both DOC and DOCX files, so you should be able to parse the files and determine what kind they are.
Looking at the link, .doc files are OLE Compound Files, the file should have the following binary header:
In constrast, .docx files will have the binary signature:
DOCX 文件采用 ZIP 格式,其中前两个字节是字母 PK(以 ZIP 的创建者 Phil Katz 的名字命名)。
DOCX files are in ZIP format, in which the first two bytes are the letters PK (after ZIP's creator, Phil Katz).