如何知道文件类型? [英] How to know the filetype?

查看:275
本文介绍了如何知道文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道文件是否音频 MP3 AAC ,等),视频 MP4 WMV 3GP 等) Document(<$c$c>txt,<$c$c>rtf,<$c$c>doc,<$c$c>docx,<$c$c>xls,<$c$c>xlsx,<$c$c>ppt,<$c$c>html等)或未知(无特异

I want to know whether the file is Audio(mp3,aac, etc), Video(mp4,wmv,3gp,etc), Document(txt,rtf,doc,docx,xls,xlsx,ppt,html etc) or Unknown (with no extension and other custom extension specific for one single application in the near future)

我要实现它在Android中。我想我能找到的文件,并确定其类型的扩展名?或者我不需要知道分机?

I need to implement it in Android. I think I could find the extension of file and identifying its type? Or do I not need to know the extension?

我只是想知道的文件类型。

I just want to know the file-type.

推荐答案

您可以尝试猜测从文件扩展名使用文件类型<一个href=\"http://developer.android.com/reference/java/net/URLConnection.html#guessContentTypeFromName%28java.lang.String%29\"相对=nofollow> guessContentTypeFromName() ,或者你可以尝试使用,以从内容猜测文件类型<一个href=\"http://developer.android.com/reference/java/net/URLConnection.html#guessContentTypeFromStream%28java.io.InputStream%29\"相对=nofollow> guessContentTypeFromStream()

You can either try to guess the file type from the filename extension using guessContentTypeFromName(), or you can try to guess the file type from the content using guessContentTypeFromStream().

这篇关于如何知道文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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