title: Cache vs Data storage for downloaded content
body: <p><p>I'm downloading some text data by issuing a HTTP GET request to server. I want to save downloaded text file to re-use it on request if it has already been downloaded. But I want to keep my data private, so that no other apps could access it. On the other hand, it would be OK if Android removed that files if there's not enough disk space.
  <p>So, my question is - should I store downloaded content in App Data folder or in cache folder? Is there any difference between two?
  <p>First, I used to save files in App Data folder, using a method like</p>
  
  <pre><code>public void save(String fileName, String data) {
      FileOutputStream fos;
      try {
          fos = mContext.openFileOutput(fileName, Context.MODE_PRIVATE);
          fos.write(data.getBytes());
          fos.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Using this method I can set Private mode for my files so that no other apps could access them. But then I thought about moving files to cache directory, I need to do something like</p>
  
  <pre><code>private void save(String filename, String data) {
      File cacheDir = new File(mContext.getCacheDir(), "app_directory");
      cacheDir.mkdir();
      try {
          FileOutputStream fos = new FileOutputStream(new File(cacheDir, filename));
          fos.write(data.getBytes());
          fos.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>I cannot set Private attribute to my files anymore, so, as I understand, any application will be able to get access to my data. Am I right?</p>
  
  <p><p>Maybe there's a way to make files in cache directory private? Or it doesn't really matter where to save files to?</p>