博客
关于我
鉴别文件是否是图片
阅读量:522 次
发布时间:2019-03-07

本文共 464 字,大约阅读时间需要 1 分钟。

@SuppressLint("DefaultLocale")public boolean checkIsImageFile(String fName) {    // 获取文件扩展名    String FileEnd = fName.substring(fName.lastIndexOf(".") + 1, fName.length()).toLowerCase();        // 检查图片格式文件    return FileEnd.equals("jpg") || FileEnd.equals("png") || FileEnd.equals("gif")            || FileEnd.equals("jpeg") || FileEnd.equals("bmp");}

这一段代码实现了对文件扩展名的检查,主要用于验证图片文件的格式。在代码中,均匀地通过lastIndexOf方法获取文件扩展名,并将其转换为小写进行比较。

这种方法简单且高效,能够快速判断给定的文件名是否属于常见图片文件格式。

转载地址:http://byfcz.baihongyu.com/

你可能感兴趣的文章
sqlserver学习笔记(三)—— 为数据库添加新的用户
查看>>
org.apache.http.conn.HttpHostConnectException: Connection to refused
查看>>
org.apache.ibatis.binding.BindingException: Invalid bound statement错误一例
查看>>
org.apache.ibatis.exceptions.PersistenceException:
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
org.springframework.beans.factory.BeanDefinitionStoreException
查看>>
org.springframework.boot:spring boot maven plugin丢失---SpringCloud Alibaba_若依微服务框架改造_--工作笔记012
查看>>
SQL-CLR 类型映射 (LINQ to SQL)
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>
org.tinygroup.serviceprocessor-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>
org/hibernate/validator/internal/engine
查看>>