java问题 为什么我使用FileInputStream类必须加throws IOException
答案:2 悬赏:20
解决时间 2021-03-12 03:51
- 提问者网友:冷天寄予
- 2021-03-11 08:29
我用FileInputStream类为什么会说没抛出异常类,为什么用其他类不用。
最佳答案
- 二级知识专家网友:滚出爷的世界
- 2021-03-11 09:34
这是windows程序的异常处理机制
建议你找毕向东的JAVA基本视频教程看看
因为你在进行文件操作的时候由多种原因造成程序崩溃,可以处理的就称之为异常处理,
throws IOException 是抛出异常,如果你不添加这种处理,编译不会通过
另外更常见的一种处理方式是用
TRY
Catch 结构处理
建议你找毕向东的JAVA基本视频教程看看
因为你在进行文件操作的时候由多种原因造成程序崩溃,可以处理的就称之为异常处理,
throws IOException 是抛出异常,如果你不添加这种处理,编译不会通过
另外更常见的一种处理方式是用
TRY
Catch 结构处理
全部回答
- 1楼网友:懂得ㄋ、沉默
- 2021-03-11 10:24
原因:你要下载的文件不存在,导致inputstream为null,所以报了这个错误;查看官方源代码,
如下:
if (inputstream == null) {
// find the inputstream from the invocation variable stack
inputstream = (inputstream) invocation.getstack().findvalue(conditionalparse(inputname, invocation));
}
if (inputstream == null) {
string msg = ("can not find a java.io.inputstream with the name [" + inputname + "] in the invocation stack. " +
"check the tag specified for this action.");
log.error(msg);
throw new illegalargumentexception(msg);
}
解决办法:
在downloadaction.java类中定义一个方法:
public inputstream getimagestream(){
return stream;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯