0

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();
 }
Jade Byfield
  • 4,668
  • 5
  • 30
  • 41
  • [This will help](http://stackoverflow.com/questions/106770/standard-concise-way-to-copy-a-file-in-java) – st0le Jan 13 '12 at 06:16

1 Answers1

1

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.

Shashank Kadne
  • 7,993
  • 6
  • 41
  • 54
  • Add this...in = new BufferedInputStream(new FileInputStream(img)); while((c = in.read())!=-1) { out.write(c); } out.flush(); – Shashank Kadne Jan 13 '12 at 05:44
  • Shasank thank you for your response I think that's what I was missing, but could you give me a detailed implentation using my code above? It would be greatly appreciated! – Jade Byfield Jan 13 '12 at 07:17