Ich habe eine ZIP-Datei in meinem Ordner "Assets", die ich in einem Ordner auf meinem Gerät 1-1 in eine ZIP-Datei kopieren möchte.Eine Zip-Datei von/assets in SD-Karte kopieren
Es funktioniert irgendwie, aber die Ausgabe zip enthält auch Sachen, die ich nicht verstehe.
Was ich habe:
Eingang:
Vermögen: Map.mp3
Ausgang:
Map.zip
Vermögen + META-INF + org + res + AndroidManifest.xml + classes.dex + resources.arsc (alle APK-Datei)
Während in Map.zip/assets gibt es eine Map.mp3 mit der ursprüngliche Inhalt. Aber ich muss nur eine Kopie 1-1 mit nur Dateierweiterung geändert haben.
Mein 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"