检测压缩文件java [英] Detect a compressed file java

查看:114
本文介绍了检测压缩文件java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,非常善于阅读这本书。

Hi everybody who is kind enough to read this.

我使用Java程序,我没有做,但im精简,这是你的问题可以添加文件,但我想验证所以添加的文件没有压缩任何人类已知的格式,所以我不想让人们能够添加一个zip文件或rar或7z或gz,等等。

Im working with a Java program, i didnt make it, but im refining it , the problem it's that you can add files , but i want to validate so the added files are not compressed in any human known format so i dont want the people to be able to add a zip file or rar or 7z or gz , an so on.

任何人都可以帮助我一个想法,这是可能吗?

can anyone help me with a idea, it's this even possible?

提前感谢。

*编辑:
IT学生使用的程序,他们添加其源代码的文件(.java,.class,.php,.doc,.mdb)被保存在字符串中,最后,程序拉链文件,并将它们发送给老师,知道教师不想接收压缩或压缩文件,这是验证的原因。

* The program its used by IT students , they add the files (.java,.class, .php, .doc, .mdb) of their source code, the paths are saved in strings, and at the end, the program zips the files, and send them to the teacher, know the instructor doesn't want to receive zipped or compressed files, that's the reason of the validation.

推荐答案

你基本上在文件的字节上执行unix命令的类型大多数文件都有嵌入的指纹,给其他程序提示它是什么类型的文件。这个指纹通常被称为魔术数字。

You basically do the java equivalent of the unix command type on the file's bytes. Most files have an embedded fingerprint which gives hints to other programs as to what type of file it is. This fingerprint is typically called a "magic number"

7zip - '7', 'z', 0xBC, 0xAF, 0x27, 0x1C
gzip - 0x1F, 0x8B

一(不完整)这里可以找到魔术数字列表

有些文件没有魔法数字,在这种情况下,你必须寻找文件中的其他常见项目,强烈地暗示它是可疑类型的文件。

Some files don't have magic numbers, in which case you have to look for other common items in the file which strongly hints it's a file of the suspected type.

依赖文件扩展名只会让所有人最终重命名扩展。

Relying on file name extensions will just have everyone eventually renaming the extension.

这篇关于检测压缩文件java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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