知道,如果一个文件是Java / Android的一个形象 [英] Know if a file is a image in Java/Android

查看:121
本文介绍了知道,如果一个文件是Java / Android的一个形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于文件路径是什么知道的最简单的方法,如果该文件是Java(Android的)一个图像(任何种类)?谢谢

Given a file path what is the easiest way of know if that file is a image (of any kind) in Java(Android)? Thanks

推荐答案

有外部工具,可以帮助你做到这一点。请查看 JMimeMagic 和的 JMagick 。您也可以尝试使用的ImageIO 类读取该文件,但可能是昂贵的,而不是完全可靠。

There are external tools that can help you do this. Check out JMimeMagic and JMagick. You can also attempt to read the file using the ImageIO class, but that can be costly and is not entirely foolproof.

BufferedImage image = ImageIO.read(new FileInputStream(new File(..._)));

这个问题已经被问上这么几次。看到这些额外的线程在同一主题:

This question has been asked on SO a couple of times. See these additional threads on the same topic:

检查文件是否

<一个href="http://stackoverflow.com/questions/4169713/how-to-check-a-uploaded-file-whether-it-is-a-image-or-other-file">How来检查上传的文件是否是一个图像或其他文件?

这篇关于知道,如果一个文件是Java / Android的一个形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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