1
我使用此代码,但它在文件outputstream处失败。 当我做一个静态无效然后getResources将失败。从原始文件夹复制图像到外部SD卡?
public void copy (Context context) {
InputStream in = getResources().openRawResource(R.raw.high1);
FileOutputStream out = new FileOutputStream("/sdcard/pic1.jpg");
byte[] buff = new byte[1024];
int read = 0;
try {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
} finally {
in.close();
out.close();
}
}
**永远不用硬编码PATHS **。使用'getExternalFilesDir()'或'Environment.getExternalStoragePublicDirectory()'或类似的东西来获取外部存储上的目录。 – CommonsWare