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