怎样用JAVA流来分割一个mp3文件代码
package xuan;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.Buffer;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
public class mp3 {
public static void cutMusic() throws IOException{
File file=new File("E:\\薛之谦 - 那是你离开了北京的生活.flac");
File file2=new File("E:\\music");
FileInputStream fis =new FileInputStream(file);
FileOutputStream fos=null;
//if(file2.exists()!=true) {
// file2.mkdirs();
//}
int len=0;
int x=0;
int y=1020*1024;
byte [] one=new byte[y];
if(file.length()%y!=0) {
x=(int)(file.length()/y+1);
}else if(file.length()%y==0) {
x=(int)(file.length()/y);
}
for(int i=1;i<=x;i++) {
len=fis.read(one);
fos=new FileOutputStream (new File(file2,i+".flac"));
fos.write(one,0,len);
}
fis.close();
fos.close();
}
public static void mergeMusic()throws IOException{
File file=new File("E:\\merge.flac");
File file2=new File("E:\\music");
// if(file.exists()!=true) {
// file.createNewFile();
// }
File[]f=file2.listFiles();
FileInputStream fis=null;
FileOutputStream fos=new FileOutputStream(file);
BufferedOutputStream bos =new BufferedOutputStream(fos,1024*1024);
int len=0;
for(int i=0;i<f.length;i++) {
fis =new FileInputStream(f[i]);
BufferedInputStream bis =new BufferedInputStream(fis,1024*1024);
while((len=bis.read())!=-1) {
bos.write(len);
}
fos.flush();
fis.close();
}
bos.close();
fos.close();
}
public static void main(String[] args) throws IOException{
cutMusic();
mergeMusic();
// TODO Auto-generated method stub
}
}