本帖最后由 wudiisss 于 2011-11-23 16:00 编辑
将e\aaa文件夹下的mp3(只有mp3文件)合并成一个文件,路径为e:\aaa.mp3
package execisetest;
import java.io.*;
import java.util.*;
public class Mp3Connect {
static List<File> list=null;
public static void main(String [] args) throws Exception{
list=new ArrayList<File>();
addMp3(new File("e:\\aaa"),list);
connect(new File("e:\\aaa.mp3"));
}
public static void connect(File f1) throws Exception{
BufferedInputStream buffIn=null;
BufferedOutputStream buffOut=new BufferedOutputStream(new FileOutputStream(f1));
int len=0;
byte [] buf=new byte[1024];
for(File mp3Name:list){
buffIn=new BufferedInputStream(new FileInputStream(mp3Name));
System.out.println("开始读取"+mp3Name);
while((len=buffIn.read(buf))!=-1){
buffOut.write(buf, 0, len);
buffOut.flush();
}
}
buffIn.close();
buffOut.close();
System.out.println("合并完成");
}
public static void addMp3(File dir,List<File> list){
File [] files=dir.listFiles();
for(File file:files){
list.add(file);
}
}
} |
|