Reputation: 12857
I'm trying to convert file *logo_image.png* in `drawable/` folder to a `File`.
The following code fails as f
is null
;
int drawableResourceId =
context.getResources().getIdentifier("logo_image",
"drawable",
context.getPackageName());
File f=new File("logo_image"+".png");
try
{
InputStream inputStream = (InputStream)
context.getResources()
.openRawResource(drawableResourceId);
OutputStream out=new FileOutputStream(f);
byte buf[]=new byte[1024];
int len;
while((len=inputStream.read(buf))>0)
out.write(buf,0,len);
out.close();
inputStream.close();
}
catch (IOException e){
}
Upvotes: 0
Views: 841
Reputation: 2798
1 . Check if you have a set the permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
2 .Set a outdirectory for the output file
3 . check if file exists otherwise call f.createNewFile();
Upvotes: 2