0

This is my first time asking a question but I hope I can get an answer. I am trying to copy an existing resource (ogg file) to another directory. I have had success with reading the file as an AudioInputStream and playing the file, but I cannot figure out how to write the file to another location. I am using vorbisspi, tritonus, jorbis, and jogg. (they all came with the vorbisspi library). Can someone please provide an example of a code to write an ogg file to another directory starting with the reading of the file as a resource? If you use any libraries, please specify. Thanks for your help.

tshepang
  • 12,111
  • 21
  • 91
  • 136
  • 2
    step back and realize that an .ogg file is a **FILE**. Don't look for "how to copy an ogg file". Look for "copy a file"... which will be a bedrock core function... – Marc B Dec 28 '13 at 17:59
  • possible duplicate of [Standard concise way to copy a file in Java?](http://stackoverflow.com/questions/106770/standard-concise-way-to-copy-a-file-in-java) – Kevin Panko Dec 28 '13 at 19:15
  • I thought sound files were different than txt files and such – XAcidMystX Dec 28 '13 at 21:13

3 Answers3

0

Change srcFile and dstFile according to your requirement. Increase buffer size (currently 1024) if required. import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream;

public class FileCopy {

public static void main(String[] args) {
    try {
        File srcFile = new File("/home/test001/sampleDir/sourcefile.wav");

        File dstFile = new File("/home/test001/sampleDir/dstFile.wav");
        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);
    }

}

}

Anirban Pal
  • 529
  • 4
  • 10
0

Have you considered using the Java API: Files.copy(Path, Path)

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
0

Copying file from one location to another has nothing to do with formats, codecs etc.

Solution:

  1. Add Apache Commons IO library to your project.

  2. Add one line of code:

    FileUtils.copyFile(src, dst);
    
akhikhl
  • 2,552
  • 18
  • 23
  • Yeah, thanks, I did not realize that all files could be copied the same. I thought sounds and were different. – XAcidMystX Dec 28 '13 at 21:12