其他分享
首页 > 其他分享> > 音乐文件合并/IO流

音乐文件合并/IO流

作者:互联网

package com.Test;

import java.io.*;

public class demo2 {
    public static void main(String[] args) throws IOException {
//        PrintWriter printWriter= new PrintWriter(new File("G:\\培训班\\代码块\\week4\\day2\\src\\com\\Test\\day3.txt"));
//        printWriter.println("qw");
//        printWriter.close();
        music();

    }

//读取两个以或以上的Mp3文件,将这些mp3文件合并到一个mp3文件中
    public static void music() throws IOException {
        File file1=new File("C:\\Users\\levovo\\Music\\青柠 - 不仅仅是喜欢.mp3");
        File file2=new File("C:\\Users\\levovo\\Music\\汪苏泷 - 般配.mp3");
        File file3=new File("C:\\Users\\levovo\\Music\\aaa.mp3");
        if(!file3.exists()){
            file3.createNewFile();
        }


        //Reader reader = new InputStreamReader(new FileInputStream(file1));
        InputStream inputStream=new FileInputStream(file1);
        InputStream inputStream2=new FileInputStream(file2);

       //ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream());

        //Writer writer=new OutputStreamWriter(new FileOutputStream(file3));
        BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(new FileOutputStream(file3));



        byte[] bytes=new byte[1024];
        int l=0;
        while ((l=inputStream.read(bytes))!=-1){
            bufferedOutputStream.write(bytes,0,l);
        }
        while ((l=inputStream2.read(bytes))!=-1){
            bufferedOutputStream.write(bytes,0,l);
        }
        inputStream.close();
        inputStream2.close();
        bufferedOutputStream.close();


    }
}

  

标签:file3,IO,音乐文件,bytes,合并,bufferedOutputStream,mp3,File,new
来源: https://www.cnblogs.com/lyl890/p/16519192.html