0

我想将存储在我的资产文件夹中的图像移动到我的 SD 卡中......

private void copyAssets() {
    AssetManager assetManager = getAssets();
    String[] files = null;
    try {
        files = assetManager.list("");
    } catch (IOException e) {
        Log.e("tag", "Failed to get asset file list.", e);
    }
    for(String filename : files) {
        InputStream in = null;
        OutputStream out = null;
        try {
          in = assetManager.open(filename);
          File outFile = new File(getExternalFilesDir(null), filename);
          out = new FileOutputStream(outFile);
          copyFile(in, out);
          in.close();
          in = null;
          out.flush();
          out.close();
          out = null;
        } catch(IOException e) {
            Log.e("tag", "Failed to copy asset file: " + filename, e);
        }       
    }
}
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);
    }
}

这是我使用的标准代码,我也在我的清单中进行了更改

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

我还在我的 java 类的 onCreate 方法中调用了上述函数但是我没有在我的管理应用程序中获得“移动到 sd 卡”选项,也没有任何文件被复制。

而是显示错误:07-11 16:59:29.042: E/tag(4997): java.io.FileNotFoundException: images

4

0 回答 0