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.