java.io.FileNotFoundException:图片

时间:2013-07-11 11:54:41

标签: android android-sdcard

我想将存储在我的资源文件夹中的图像移动到我的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);
    }
}

这是我使用的标准代码,我已经在我的MANIFEST中进行了更改

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

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

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

0 个答案:

没有答案