3

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 buffreader = 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 ");
 }
}
     }

}
ismail
  • 46,010
  • 9
  • 86
  • 95
xarph
  • 31
  • 1
  • 2
  • 1
    Please read this: http://stackoverflow.com/questions/939170/resources-openrawresource-issue-android – gulbrandr Jan 14 '11 at 12:02
  • Thanks. I discover DataInputStream and DataOutputStream did the trick is so far as not messing up the transferred data. – xarph Jan 14 '11 at 20:59

0 Answers0