Android将照片从一个文件夹移动到另一个文件夹

时间:2012-01-13 01:56:08

标签: android file-io photo android-sdcard

我正在使用以下代码将图像从外部存储器上的一个文件夹传输到另一个用户指定的文件夹。问题是,照片​​被复制到目标文件夹正常..但我无法打开或查看它。我使用名为Astro的文件管理器来查看它是否已成功移动,它是..但我无法在Astro和常驻Gallery应用程序中打开它。我在想我的代码有问题,也许我需要先阅读和/或解码才能移动它,从我对File类的理解它只是一个抽象。任何有关这方面的指导都将非常感激,这是我目前正在使用的代码。

 File img = new File(imgViewPath);

    File output = new
                              File(Environment.getExternalStorageDirectory().toString() + "/MyAppPics/" + moved,
                         img.getName()); 


OutputStream out = null;
try {
   out = new BufferedOutputStream(new FileOutputStream(output));
        }
 finally {
 if (out != null) {
      out.close();
}
}
}catch(Exception e){
                                     e.printStackTrace();
 }

1 个答案:

答案 0 :(得分:1)

您没有在输出流中写任何内容。从输入流中读取字节并将其写入输出流,然后才会复制文件。