0
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){
}
你得到了什么drawableResourceId? – Luciano
@Luizje图片的ID logo_image.png – NickUnuchek
好的,所以不是0.你有没有在清单中设置权限?你为什么不设置文件的目录?如果文件不存在,应该先创建文件? – Luciano