2016-03-19 16 views
0

私の資産フォルダに.zipファイルがあります。このファイルは、デバイス上のフォルダの.zipに1-1をコピーしたいものです。/assetsからsdcardにジップをコピーする

作品の種類ですが、出力ジップにもわからないものが含まれています。

私が持っているもの

入力:

資産: Map.mp3

出力:

Map.zip

資産+ META-INF + ORG + RES +の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"

答えて

0

あなたは常に単純なファイルコピー手順を使用することができます。

private void copyFile(InputStream in, OutputStream out) throws IOException { 
    byte[] buffer = new byte[1024]; 
    int read; 
    while((read = in.read(buffer)) != -1){ 
     out.write(buffer, 0, read); 
    } 
} 

FileDescriptorの使用方法は、圧縮ファイルでは機能しません。 私が理解するように、あなたはthat answerからそのような解決策を得ます。以下 コメントは、

私のソリューションは、.MP3への拡張の名前を変更することをお勧め

がで12月19日'12によって日付がコピーされた一回 それを削除し、.MP3する拡張子を変更しました2:07 GoogleはFileDescriptorの使用方法を変更し、名前を変更してthrickを終了することがあります。

私はAndroidプロジェクトで簡単な手順を使用していますが、すべて正常に動作しますが、パフォーマンス上の問題はありません。

関連する問題