当前位置:网站首页>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")));
}
边栏推荐
- [rtklib 2.4.3 B34] version update introduction I
- Fairygui character status Popup
- Combination of fairygui check box and progress bar
- 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
- [algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
- MySQL shutdown is slow
- RTKLIB: demo5 b34f.1 vs b33
- 音乐播放(Toggle && PlayerPrefs)
- Naive Bayesian theory derivation
- 染色法判定二分图
猜你喜欢
服务未正常关闭导致端口被占用
【干货】提升RTK模糊度固定率的建议之周跳探测
[Chongqing Guangdong education] Shandong University College Physics reference materials
Unity scene jump and exit
2022国赛Re1 baby_tree
FairyGUI复选框与进度条的组合使用
基本Dos命令
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
Prove the time complexity of heap sorting
随机推荐
基本Dos命令
wsl常用命令
Fairygui loop list
MySQL error warning: a long semaphore wait
Detailed explanation of balanced binary tree is easy to understand
Devops' future: six trends in 2022 and beyond
RTKLIB: demo5 b34f. 1 vs b33
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
121道分布式面试题和答案
FGUI工程打包发布&导入Unity&将UI显示出来的方式
染色法判定二分图
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
Chromatic judgement bipartite graph
RTKLIB: demo5 b34f.1 vs b33
FairyGUI复选框与进度条的组合使用
Agile development helps me
Rt-ppp test using rtknavi
Office提示您的许可证不是正版弹框解决
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT