I have a .zip file in my assets folder, which I want to copy 1-1 to a .zip in a folder on my device.
It kind of works, but the output zip contains also stuff that I do not understand.
What I have:
Input:
assets: Map.mp3
Output:
Map.zip
assets+META-INF+org+res+AndroidManifest.xml+classes.dex+resources.arsc (all APK file)
Whereas in Map.zip/assets there is a Map.mp3 with the initial content. But I just need to have a 1-1 copy with just file extension changed.
My code:
//taken from: http://stackoverflow.com/questions/4447477/android-how-to-copy-files-from-assets-folder-to-sdcard
AssetManager assetManager = getAssets();
AssetFileDescriptor assetFileDescriptor = null;
try
{
assetFileDescriptor = assetManager.openFd("Map.mp3");
// Create new file to copy into.
File output= new File(_FILEPATH_ + java.io.File.separator + "Map.zip");
output.createNewFile();
copyFdToFile(assetFileDescriptor.getFileDescriptor(), output);
}
catch (IOException e)
{
e.printStackTrace();
}
public static void copyFdToFile(FileDescriptor src, File dst) throws IOException {
FileChannel inChannel = new FileInputStream(src).getChannel();
FileChannel outChannel = new FileOutputStream(dst).getChannel();
try {
inChannel.transferTo(0, inChannel.size(), outChannel);
} finally {
if (inChannel != null)
inChannel.close();
if (outChannel != null)
outChannel.close();
}
}
_FILEPATH_
=Environment.getExternalStorageDirectory().getAbsolutePath()+"/osmdroid"