确定byte []是否为pdf文件 [英] Determine if a byte[] is a pdf file

查看:289
本文介绍了确定byte []是否为pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检查byte []是否为pdf而无需打开?

Is there any way of checking if a byte[] is a pdf without opening?

我有一些代码可以将byte []列表显示为pdf缩略图.我以前知道所有的byte []都是pdf的,因为我们过滤了servlet以便仅返回它们.现在要求已更改,我需要恢复所有文件类型.有什么方法可以检查byte []是什么,或更具体地确定它是否不是pdf?

I have some code to display a list of byte[] as pdf thumbnails. I previously knew all the byte[] were pdf's because we filtered the servlet to only return these. Now the requirement has changed and I need to bring all file types back. Is there any way of checking what the byte[] is, or more specifically determining if it isn't, a pdf?

推荐答案

检查数组的前4个字节.

Check the first 4 bytes of the array.

如果这些文件是0x25 0x50 0x44 0x46,则很可能是PDF文件.

If those are 0x25 0x50 0x44 0x46 then it's most probably a PDF file.

这篇关于确定byte []是否为pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆