今天在做文件上传的时候遇到一个这样的问题

java.lang.ClassCastException: java.io.ByteArrayInputStream cannot be cast to java.io.FileInputStream

具体出错的代码:

FileInputStream fileInputStream = (FileInputStream)diskFileItems[i].getInputStream();

其中diskFileItems是DiskFileItem[]数组对象,DiskFileItem是Apache的commons-fileupload包里的一个类

在CSDN啥的上面没有找到一个类似的错误,所以直接跑到Stack Overflow上去找,一下就发现了错误的原因,这里的解决办法是:

把FileInputStream改成InputStream就好了

java.lang.ClassCastException: java.io.ByteArrayInputStream cannot be cast to java.io.FileInputStream的更多相关文章

  1. java.lang.ClassCastException: oracle.sql.TIMESTAMP cannot be cast to java.sql.Timestamp

    http://stackoverflow.com/questions/13269564/java-lang-classcastexception-oracle-sql-timestamp-cannot ...

  2. java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView

    最近在学习drawerLayout时,遇到这个bug.如下示: java.lang.ClassCastException: android.widget.RelativeLayout cannot b ...

  3. 关于android使用ksoap2报Caused by: java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject

    Caused by: java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serializa ...

  4. java.lang.ClassCastException: oracle.sql.CLOB cannot be cast to oracle.sql.CLOB

    错误现象: [framework] 2016-05-26 11:34:53,590 -INFO  [http-bio-8080-exec-7] -1231863 -com.dhcc.base.db.D ...

  5. java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText

    Caused by: Java.lang.ClassCastException: Android.widget.TextView cannot be cast to android.widget.Ed ...

  6. 安卓出现错误: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText

    Caused by: Java.lang.ClassCastException: Android.widget.TextView cannot be cast to android.widget.Ed ...

  7. java.lang.ClassCastException:android.widget.Button cannot be cast to android.widget.ImageView

    今天遇到一个错误也不知道怎么回事,上网搜了一下: 出现的问题是:java.lang.ClassCastException:android.widget.Button cannot be cast to ...

  8. java.lang.ClassCastException: android.app.Application cannot be cast to

    出这个异常的原因是在项目中添加了新lication类(public class Application extends lication)之后,没有在AndroidManifest.xml中添加该类的 ...

  9. Android: java.lang.ClassCastException: android.widget.imageView cannot be cast to android.widget.textView异常解决

    有时在修改xml文件时,全报这种错误,这个应该是缓存没得到及时更新导致的,可以通过以下方法解决: Eclipse tends to mess up your resources every now a ...

随机推荐

  1. thinkphp 数据写入

    直线电机优势 ThinkPHP的数据写入操作使用add方法,使用示例如下: $User = M("User"); // 实例化User对象 $data['name'] = 'Thi ...

  2. JDK源码阅读--HashMap

    public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, ...

  3. java加拼音的工具 pinyinutil

    <!--汉字转拼音--> <dependency> <groupId>com.belerweb</groupId> <artifactId> ...

  4. linux socket error code

    errno.00 is: Successerrno.01 is: Operation not permittederrno.02 is: No such file or directoryerrno. ...

  5. rsync命令集合

    rsync -avz rsync://logs@211.151.78.206/www_logs/2014/03/27/* /mnt/hgfs/iautoslogs/

  6. Python学习之while练习--九九乘法表

    效果如下: 实现代码; m = 1n = 1while(m<10): while(n<=m): print(n,"*",m,"=",m*n,end ...

  7. Tornado demo3 - tcpecho分析

    在这个demo中,主要是使用了Tornado中异步的TCP client和server来实现一个简单的echo效果(即客户端发送的message会从server端返回到client).代码的githu ...

  8. mongodb什么时候使用

    转自:https://blog.csdn.net/justlpf/article/details/80392944 简介 MongoDB[1] 是一个基于分布式文件存储的数据库.由C 语言编写.旨在为 ...

  9. [转]Visual Studio 2010单元测试(2)--运行测试并查看代码覆盖率

    Visual Studio 2010 单元测试--运行测试并查看代码覆盖率 运行测试并查看代码覆盖率对程序集中的代码运行测试时,可以通过收集代码覆盖率数据来查看正在测试的项目代码部分. 运行测试并查看 ...

  10. 19-10-24-J-快乐?

    向未来的大家发送祝福(不接受的请自动忽略): 祝大家程序员节快乐! 好了. ZJ一下 额. 考场上差点死了. 码1h后,T1还没过大样例. 我×××. 后来发现是自己××了. T2T3丢暴力. 比咕的 ...