当前位置:网站首页>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")));
}
边栏推荐
- [Chongqing Guangdong education] Shandong University College Physics reference materials
- [算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组
- [算法] 剑指offer2 golang 面试题9:乘积小于k的子数组
- Office prompts that your license is not genuine pop-up box solution
- 【GNSS】抗差估计(稳健估计)原理及程序实现
- Fairygui gain buff value change display
- MySQL error warning: a long semaphore wait
- Matlab读取GNSS 观测值o文件代码示例
- 记录:Navicat Premium初次无法连接数据库MySQL之解决
- Wechat applet development experience
猜你喜欢
【干货】提升RTK模糊度固定率的建议之周跳探测
NovAtel 板卡OEM617D配置步骤记录
Wechat applet development experience
[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K
FairyGUI增益BUFF數值改變的顯示
The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25
音乐播放(Toggle && PlayerPrefs)
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
[算法] 剑指offer2 golang 面试题4:只出现一次的数字
[algorithm] sword finger offer2 golang interview question 1: integer division
随机推荐
FairyGUI循环列表
FairyGUI条子家族(滚动条,滑动条,进度条)
GNSS positioning accuracy index calculation
Fabrication d'un sac à dos simple fairygui
It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
What are the advantages of using SQL in Excel VBA
FairyGUI复选框与进度条的组合使用
编辑距离(多源BFS)
Database table splitting strategy
GPS高程拟合抗差中误差的求取代码实现
Devops' future: six trends in 2022 and beyond
Code example of MATLAB reading GNSS observation value o file
Fairygui joystick
Mixed use of fairygui button dynamics
Prove the time complexity of heap sorting
微信小程序开发心得
Sharing ideas of on-chip transplantation based on rtklib source code
Wechat applet development experience
[Chongqing Guangdong education] Shandong University College Physics reference materials
地球围绕太阳转