当前位置:网站首页>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")));
}
边栏推荐
- Meanings and differences of PV, UV, IP, VV, CV
- Special palindromes of daily practice of Blue Bridge Cup
- Heap sort [handwritten small root heap]
- Naive Bayesian theory derivation
- (the first set of course design) sub task 1-5 317 (100 points) (dijkstra: heavy edge self loop)
- Itext 7 生成PDF总结
- Role movement in the first person perspective
- (core focus of software engineering review) Chapter V detailed design exercises
- Force buckle 1189 Maximum number of "balloons"
- 【无标题】
猜你喜欢
![[untitled]](/img/b1/9a2bebebb24132a405fc4e7d854e51.png)
[untitled]
![[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire](/img/c2/6f6c3bd4d70252ba73addad6a3a9c1.png)
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire

Wechat applet development experience

Fairygui joystick

121道分布式面试题和答案

Theoretical derivation of support vector machine

Implementation of Excel import and export functions

《软件测试》习题答案:第一章

Rt-ppp test using rtknavi

Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
随机推荐
KF UD decomposition pseudo code implementation advanced [2]
C programming exercise
Fairygui joystick
错误: 找不到符号
Comparative analysis of the execution efficiency of MySQL 5.7 statistical table records
Liste des boucles de l'interface graphique de défaillance
[algorithm] sword finger offer2 golang interview question 2: binary addition
Fairygui gain buff value change display
Detailed explanation of balanced binary tree is easy to understand
InnoDB dirty page refresh mechanism checkpoint in MySQL
Lock wait timeout exceeded try restarting transaction
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
Compile GDAL source code with nmake (win10, vs2022)
Guided package method in idea
【GNSS】抗差估计(稳健估计)原理及程序实现
FGUI工程打包发布&导入Unity&将UI显示出来的方式
MySQL error warning: a long semaphore wait
Teach you to release a DeNO module hand in hand
记录:Navicat Premium初次无法连接数据库MySQL之解决
[算法] 劍指offer2 golang 面試題2:二進制加法