尝试使用 InputStream 读取可绘制文件 name.png 时出现错误。为什么?

I'm getting an error while trying to read drawable file name.png using InputStream. Why?

InputStream is = getResources().openRawResource(R.drawable.name);
OutputStream os = new FileOutputStream(file);
byte[] data = new byte[is.available()];
is.read(data);
os.write(data);

R.drawble 出现 "Content mismatch"

错误

将您的资源移至 res/raw/,然后按原样使用 openRawResource(),用于 R.raw.name

或者,将您的资源移动到 assets/,然后在 AssetManager 上使用 open() 来获取您的 InputStream