在Java应用程序中确定文档是DOC还是DOCX而不知道其扩展名

发布于 2024-09-05 11:05:34 字数 160 浏览 3 评论 0原文

内容管理系统有一个限制,要求存储具有特定扩展名(不同于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许久 2024-09-12 11:05:34

此处是 ForensicsWiki 的链接,其中详细介绍了许多不同的文件类型。它描述了 DOC 和 DOCX 文件的标头,因此您应该能够解析文件并确定它们是什么类型。

查看链接,.doc 文件是 OLE 复合文件,该文件应具有以下二进制标头:

d0 cf 11 e0 a1 b1 1a e1

相反,.docx 文件将具有二进制签名:

50 4b

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:

d0 cf 11 e0 a1 b1 1a e1

In constrast, .docx files will have the binary signature:

50 4b
却一份温柔 2024-09-12 11:05:34

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文