Android, Copy .png file form res.raw to App's private internal memor
I need to copy a PNG file form res.raw my App's private internal memory. This is code I am using. The resulting file appears to be corrupt in that BitmapFactory.decodeFile() returns null. The same file, if placed on the SD Card decodes just fine. Here is the code that I am using.
private void loadGraphics(){
InputStream inputStream = BasicContext.getResources().openRawResource(R.raw.galaxy);
InputStreamReader inputreader = new InputStreamReader(inputStream);
BufferedReader buf开发者_高级运维freader = new BufferedReader(inputreader, 8192);
int Byte = 0;
FileWriter writer = null;
String PathA = "/sdcard/rfo-basic/data/Galaxy1.png";
try {
writer = new FileWriter(PathA);
do {
Byte = buffreader.read();
{writer.write(Byte);}
} while (Byte != -1);
} catch (IOException e) {
Log.v(Basic.LOGTAG, " " + Basic.CLASSTAG + " I/O Exception 2 ");
}
finally {
if (writer != null) {
try {
writer.flush();
writer.close();
} catch (IOException e) {
Log.v(Basic.LOGTAG, " " + Basic.CLASSTAG + " I/O Exception 4 ");
}
}
}
}
精彩评论