获取真正的文件扩展名-Java代码 [英] Get real file extension -Java code

查看:842
本文介绍了获取真正的文件扩展名-Java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于安全原因,我想确定真正的文件扩展名。

I would like to determine real file extension for security reason.

我该怎么做?

推荐答案

假设你真的想要获取文件的真实内容类型(即它的MIME类型),你应该参考这个优秀答案

Supposing you really mean to get the true content type of a file (ie it's MIME type) you should refer to this excellent answer.

您可以获得真实的内容类型使用以下代码编写Java文件:

You can get the true content type of a file in Java using the following code:

File file = new File("filename.asgdsag");
InputStream is = new BufferedInputStream(new FileInputStream(file));
String mimeType = URLConnection.guessContentTypeFromStream(is);

这篇关于获取真正的文件扩展名-Java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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