Friday, June 10, 2011

Java: Write to File: Copy Bytes: Copy Music


import java.io.*;
import java.io.File;
import javax.sound.sampled.*;

public class InOut {

public static void main(String[] args) {
 try {
      File srcFile = new File("earthmovers1.mp3");
      File dstFile = new File("earthmovers2.mp3");
      FileInputStream in = new FileInputStream(srcFile);
      FileOutputStream out = new FileOutputStream(dstFile);

      byte[] buf = new byte[1024];
      int len;
      while ((len = in.read(buf)) > 0) { 
                                   out.write(buf, 0, len);
                                       }

     in.close();
     out.close();

   } catch ( Exception e ) {System.out.println( e );}


    }
}

No comments: