2

I have a PNG image file in my assets folder. I need to copy that file to the device. Currently I am using this method and it is not working.

I have declared the PNG location like this

pngLocation = "file:///android_asset/image.png";

Here I try to copy the file to the device

String sourcePath = pngLocation;
 root = Environment.getExternalStorageDirectory().toString();
        File source = new File(sourcePath);
        File f = new File(root+ "/MyDirectory/");
        if(f.isDirectory()) {
            pngLocation = f.getAbsolutePath()+"/image.png";
        }else {
            File folder = new File(root+"/MyDirectory/");
            folder.mkdirs();
            pngLocation = f.getAbsolutePath()+"/image.png";
        }
        File destination = new File(pngLocation);
        try
        {
            FileUtils.copyFile(source, destination);
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

I don't receive any error but the file in not copied. Have I missed out something ? Thanks in advance.

Kalai Arasi
  • 249
  • 1
  • 6
  • 16
  • 1
    Check out [this answer](http://stackoverflow.com/a/10623968/1715829) for how to copy a file out of the assets directory. – Buddy Jun 06 '15 at 04:26

0 Answers0