package cn.cm.conse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
import java.util.Enumeration;
import java.util.Vector;
//切割mp3成三份,之后合并
public class Demo01 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
method();
stx();
}
public static void method() throws FileNotFoundException, IOException {//分割为3份mp3
File file=new File("E:\\CloudMusic\\123.mp3");
FileInputStream input=new FileInputStream(file);
byte[] b=new byte[1024*1024];
int length=0;
File files=new File("E:\\music");
for(int i=0;((length=input.read(b))!=-1);i++){
File fi=new File(files,i+".mp3");
FileOutputStream filed=new FileOutputStream(fi);
filed.write(b, 0, length);
filed.close();
}
input.close();
}
public static void stx() throws IOException{
File dir=new File("E:\\music");
Vector<FileInputStream> vector=new Vector<FileInputStream>();
File file[]=dir.listFiles();
for(File fi:file){
if(fi.getName().endsWith(".mp3")){//别忘了mp3后有两个括号
vector.add(new FileInputStream(fi));
} }
Enumeration<FileInputStream> e=vector.elements();
SequenceInputStream input=new SequenceInputStream(e);
FileOutputStream out=new FileOutputStream("F:\\");
byte[] b=new byte[1024];
int length=0;
while((length=input.read(b))!=-1){
out.write(b,0,length);
}
out.close();
input.close();
}}
把mp3分成n份之后合并
最新推荐文章于 2023-01-13 21:01:23 发布