我的資產文件夾中有一個.zip文件,我想將1-1複製到設備上的.zip文件夾中。從/ assets複製ZIP到SD卡
這種作品,但輸出zip也包含我不明白的東西。
我有什麼:
輸入:
資產: Map.mp3
輸出:
Map.zip
個資產+ META-INF +組織+資源+的AndroidManifest.xml + classes.dex + resources.arsc(所有APK文件)
而在Map.zip/assets有一個Map.mp3最初的內容。但我只需要有一個1-1副本,只是文件擴展名已更改。
我的代碼:
//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」