title: Bitmaps Not Being Saved to Internal Storage (Android)
body: <h2>Problem</h2>
  <p>I am creating an Android app within Android Studio using Java. It needs a function that takes a bitmap image and saves it to a folder structure in internal memory. The images I'm working with are PNGs. My current implementation is based on the answer found <a href="https://stackoverflow.com/questions/17674634/saving-and-reading-bitmaps-images-from-internal-memory-in-android">here (Saving and Reading Bitmaps/Images from Internal memory in Android)</a>. I am very lost as to why not all of the log statements are being executed and no files are being created:</p>
  <pre><code>    private String saveToInternalStorage( Bitmap bitmapImage, String dataType, int zoom, int x, int y )
      {
          Log.w(TAG, &quot;Function Started.&quot;);
          String imageDir = String.format( &quot;%s/%d/%d&quot;, dataType, zoom, x );
          String imageName = String.format( &quot;%d.png&quot;, y );
  
          ContextWrapper contextWrapper = new ContextWrapper( getContext() );
          Log.w(TAG, &quot;Passed Context Wrapper.&quot;);
  
          // path to /data/data/app_name/app_data/&lt;dataType&gt;/&lt;zoom&gt;/&lt;x&gt;
          // - - - NO LOGS SHOWN PAST THIS POINT - - -
          File directory = contextWrapper.getDir( imageDir, Context.MODE_PRIVATE );
          Log.w(TAG, &quot;Passed Directory Creation.&quot;);
  
          // Create image at imageDir (&lt;y&gt;.png)
          File imageFile = new File( directory, imageName );
          Log.w(TAG, &quot;Passed File Creation.&quot;);
  
          FileOutputStream outputStream = null;
          Log.e(TAG, &quot;Begining to Output to File.&quot;);
          try
          {
              outputStream = new FileOutputStream( imageFile );
              // Use the compress method on the BitMap object to write image to the OutputStream
              bitmapImage.compress( Bitmap.CompressFormat.PNG, 100, outputStream );
          }
          catch( Exception e )
          {
              Log.e(TAG, &quot;Error Adding Image to Internal Storage.&quot;);
              e.printStackTrace();
          }
          finally
          {
              try
              {
                  outputStream.flush();
                  outputStream.close();
              }
              catch( Exception e )
              {
                  Log.e(TAG, &quot;Error Closing Output Stream.&quot;);
                  e.printStackTrace();
              }
          }
  
          return directory.getAbsolutePath();
      }
  </code></pre>
  <p>The following two lines are the only relevant output shown in Logcat. <strong>I am not shown any errors and no other logs from the above function are shown</strong>.</p>
  <pre><code>2022-02-08 02:52:56.433 18914-18990/com.example.biomapper W/ContentValues: Function Started.
  2022-02-08 02:52:56.434 18914-18990/com.example.biomapper W/ContentValues: Passed Context Wrapper.
  </code></pre>
  <h2>What I've Tried</h2>
  <p>This is my third attempt at creating this function, and the closest I've gotten to making it work. I have looked at many other questions on Stack Overflow regarding this topic. I added many log statements to see where/what might be going wrong. I've tried using the <code>file.exists()</code> command to  test if the file(s) were ever created. I am sure that the parameters given to this function when testing it are correct.</p>
  <p>Any advice on saving images to internal storage, checking if the files exist, or improving my code in any way are greatly appreciated.</p>