Android, copy the .png res.raw form file to the application's personal closure

I need to copy the res.raw PNG file to my application internal memory. This is the code I'm using. The resulting file looks corrupted since BitmapFactory.decodeFile () returns null. The same file, if it is located on an SD card, decodes just fine. Here is the code I'm 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 ");
 }
}
     }

}
+3
source share

Source: https://habr.com/ru/post/1785422/


All Articles