调用f.createNewFile();
I'm trying to convert file *logo_image.png* in `drawable/` folder to a `File`.
以下代码失败,因为f
是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){
}
1。检查是否设置了权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
2 .设置输出文件的输出目录
3。