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.
Asked
Active
Viewed 119 times
0
-
2step 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 Answers
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
-
-
Thank you SOOO much, I had no idea it was this simple, I would upvote you but I don't have enough reputation apparently!! Thank you so much! I thought writing an ogg file would be different for some reason. THANKS – XAcidMystX Dec 28 '13 at 18:34
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:
Add Apache Commons IO library to your project.
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