File f1 = new File("C:\\music.mp3");
File f2 = new File("C:\\copied_file.mp3");
FileImageInputStream fileImageInputStream = new FileImageInputStream(f1);
FileImageOutputStream fileImageOutputStream = new FileImageOutputStream(f2);
int k = 0;
while(true){
System.out.println("iteration:"+k++);
if(f1.length()<f2.length())
fileImageOutputStream.write(fileImageInputStream.read());
else break;
}
Elaborate the function or the expected output of the code so that we may point you in the right direction...
Sébastien Portebois
Software architect at Ubisoft
Using
shutilis the easiest way (here withcopyfile, but you might want to look at the documentation to compare it with the other copy___ functions, depending on what you want to copy (only the binary data, the permissions, ...)import shutil shutil.copyfile('music.mp3', 'copied_file.mp3')For the record, when the file is small (ie it can be loaded in memory and streams are not required), it's even easier:
with open('music.mp3', 'rb') as f1: with open('copied_file.mp3', 'wb') as f2: f2.write(f1.read())