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

发布于 2024-12-26 18:59:56 字数 709 浏览 2 评论 0原文

我使用下面的代码将图像从外部存储器上的一个文件夹传输到另一个文件夹......按照用户指定。问题是,照片​​被复制到目标文件夹很好..但我无法打开或查看它。我使用名为 Astro 的文件管理器来查看它是否已成功移动,确实如此。但我无法在 Astro 和驻留图库应用程序中打开它。我认为我的代码有问题,也许我需要读取和/或解码照片才能移动它,根据我对 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();
 }

I'm using the below code to transfer an image from one folder on external memory, to another..as specified by the user. The problem is, the photo gets copied to the destination folder fine..but I can't open or view it. I use a file manager named Astro to see if it was successfully moved, and it is..but I'm unable to open it both in Astro and in the resident Gallery app. I'm thinking something is wrong with my code and maybe I need read and/or decode to photo before I can move it, from what I understand about the File class it is just an abstraction. Any guidance on this would be greatly appreciated, here is the code I'm currently using.

 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();
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独难免 2025-01-02 18:59:56

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

You are not writing anything to the output stream. Read the bytes from the input stream and write it to the output stream, only then the files will get copied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文