我正在尝试将输入流写入文件,但它永远不会被写入磁盘,我只是得到错误文件不存在。我打开的文件是项目中包含的可绘制文件,我想将其保存到 sd 卡。这是我到目前为止所拥有的:
File storagePath = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/tester");
InputStream inputStream = getResources().openRawResource(R.drawable.test);
OutputStream out = new FileOutputStream(new File(storagePath, "test.png"));
byte buffer[] = new byte[900];
int len;
while ((len = inputStream.read(buf)) > 0)
out.write(buffer, 0, len);
out.close();
inputStream.close();