当前位置:网站首页>Exception: ioexception:stream closed
Exception: ioexception:stream closed
2022-07-06 12:59:00 【Non wind thought】
Abnormal prompt
Exception in thread “main” java.io.IOException: Stream Closed
The stream is shut down .
The code is as follows
It's written that one or more are cut MP3 Merge the files into one MP3 file .
public class MergeFileDemo{
public static void main(String[] args) throws IOException {
File dir=new File("gril");
mergeFile(dir);
}
public static void mergeFile(File dir) throws IOException {
//
ArrayList<FileInputStream> al=new ArrayList<FileInputStream>();
for (int i = 1; i <= 5; i++) {
al.add(new FileInputStream(new File(dir,i+".part")));
Enumeration<FileInputStream> en=Collections.enumeration(al);
SequenceInputStream sis=new SequenceInputStream(en);
FileOutputStream fos=new FileOutputStream(new File(dir," Beggars' sect theme .mp3"));
byte[] buf=new byte[1024];
int len=0;
while((len=sis.read(buf))!=-1) {
fos.write(buf,0,len);
}
fos.close();
sis.close();
}
}
}
Problem analysis
The flow must be closed fos.close(); and sis.close(); Something went wrong. , After careful inspection, it is found that the closed stream is written in for Inside the loop , The flow is turned off at the first cycle . And this for Add all files when looping al.add(); It's over , The following code is also written here , So it caused an exception .
resolvent
fos.close();
sis.close();
Write the flow closure in for Outside of the loop . take for The cyclic code block is modified to the following , Also is to } Put it in al.add(); Back .
for (int i = 1; i <= 5; i++) {
al.add(new FileInputStream(new File(dir,i+".part")));
}
边栏推荐
- It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
- RTKLIB: demo5 b34f. 1 vs b33
- [Chongqing Guangdong education] Shandong University College Physics reference materials
- NovAtel 板卡OEM617D配置步骤记录
- Shortest Hamilton path (pressure DP)
- Fairygui character status Popup
- [algorithm] sword finger offer2 golang interview question 7: 3 numbers with 0 in the array
- Realization of the code for calculating the mean square error of GPS Height Fitting
- The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan
- Particle system for introduction to unity3d Foundation (attribute introduction + case production of flame particle system)
猜你喜欢
【干货】提升RTK模糊度固定率的建议之周跳探测
Excel导入,导出功能实现
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
第一人称视角的角色移动
Unity3D,阿里云服务器,平台配置
地球围绕太阳转
The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan
记录:初次cmd启动MySQL拒接访问之解决
Unity3d, Alibaba cloud server, platform configuration
FairyGUI条子家族(滚动条,滑动条,进度条)
随机推荐
[算法] 剑指offer2 golang 面试题1:整数除法
Devops' future: six trends in 2022 and beyond
最短Hamilton路径 (状压DP)
KF UD分解之伪代码实现进阶篇【2】
PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
C programming exercise
MySQL error warning: a long semaphore wait
FairyGUI人物状态弹窗
Naive Bayesian theory derivation
Prove the time complexity of heap sorting
Realization of the code for calculating the mean square error of GPS Height Fitting
抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现
Heap sort [handwritten small root heap]
[算法] 剑指offer2 golang 面试题6:排序数组中的两个数字之和
3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法
In 2020, the average salary of IT industry exceeded 170000, ranking first
[算法] 剑指offer2 golang 面试题10:和为k的子数组
Pride-pppar source code analysis
Compile GDAL source code with nmake (win10, vs2022)
Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY