title: Android Camera2 API - Overwrite old images
body: <p>I am using the code given at <a href="https://github.com/googlesamples/android-Camera2Basic" rel="nofollow noreferrer">https://github.com/googlesamples/android-Camera2Basic</a>
  and images are being saved in the activity storage with</p>
  
  <pre><code>    @Override
      public void run() {
          ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
          byte[] bytes = new byte[buffer.remaining()];
          buffer.get(bytes);
          FileOutputStream output = null;
          try {
              output = new FileOutputStream(mFile, false);
              output.write(bytes);
              output.flush();
          } catch (IOException e) {
              e.printStackTrace();
          } finally {
              mImage.close();
              if (null != output) {
                  try {
                      output.close();
                      buffer.clear();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
      }
  </code></pre>
  
  <p>given by the sample code. If I delete the images with </p>
  
  <pre><code>   File image_directory = getFilesDir();
      if (image_directory != null) {
          File[] images_list = image_directory.listFiles();
          for (int i = 0; i &lt; images_list.length; i++) {
              try {
                  //Delete the images files in the given folder
                  images_list[i].delete();
                  Log.e(TAG, "[-] File deleted with filename: " + images_list[i].getName());
              } catch (Exception e) {
              }
          }
      }
  </code></pre>
  
  <p>and take new images <strong>with the same filename as before</strong>, the old images show up. What`s happening here?</p>