title: Save internal file in my own internal folder in Android
body: <p>I try to save a txt file in my folder, in internal storage, but I face the same problem every time:</p>
  
  <blockquote>
    <p>"Source Not Found"</p>
  </blockquote>
  
  <p>I write my code in different ways expressed here as follows but in all ways I have the same problem.</p>
  
  <p>It is worth saying that I even add   </p>
  
  <p><code>&lt;uses-permission   android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;</code> </p>
  
  <p>in Manifest.xml that is not  necessary for internal storage.</p>
  
  <p>It is needless to say that I don't have any problem to save files in <em>/data/data/package/files</em> path, but when I add my folder in the files' root for example <em>/data/data/package/files/myforlder/myfile.txt</em> I face the "Source Not Found" problem. </p>
  
  <p>Could you point me in right direction to solve this ?</p>
  
  <p>The second question is that, for saving a file in an external folder in external storage.<br>
  (for example: sdCard or USB storage) is the scenario different or is it same ?</p>
  
  <p><strong>First Way:</strong></p>
  
  <pre><code>OutputStreamWriter out;
  try {
      File path=new File(getFilesDir(),"myfolder");
      File mypath=new File(path,"myfile.txt");
      if (!mypath.exists()) {
          out = new OutputStreamWriter(openFileOutput( mypath.getAbsolutePath() , MODE_PRIVATE));
          out.write("test");
          out.close();
      }                           
  }
  </code></pre>
  
  <p><strong>Second way:</strong></p>
  
  <pre><code>OutputStreamWriter out;
  try {
      ContextWrapper cw = new ContextWrapper(this);
      File path = cw.getDir("myfolder", Context.MODE_PRIVATE);
      if (!path.exists()) {
          path.createNewFile();
          path.mkdir();
      }
      File mypath=new File(path,"myfile.txt");
      if (!mypath.exists()) {
          out = new OutputStreamWriter(openFileOutput( mypath.getAbsolutePath() , MODE_PRIVATE));
          out.write("test");
          out.close();
      }
  }
  </code></pre>
  
  <p><strong>Third way:</strong></p>
  
  <pre><code>File path=getFilesDir();
  String mypath=path.toString() + "/myfolder";
  OutputStreamWriter out;
  try {
      File  f = new File(mypath , "/myfile.txt"   );
  out = new OutputStreamWriter(openFileOutput(f.getPath(), MODE_PRIVATE));
       out.write("test");
       out.close();                   
       }
  </code></pre>
  
  <p><strong>Fourth Way:</strong></p>
  
  <pre><code>File path=getFilesDir();
  
  OutputStreamWriter out;
      try {
      File f = new File(path.getPath() + "/myfolder/myfile.txt"   );
      out = new OutputStreamWriter(openFileOutput(f.getPath(), MODE_PRIVATE));
      out.write("test");
      out.close();                    
      }
  </code></pre>
  
  <p><strong>Fifth way:</strong></p>
  
  <pre><code>File path=getFilesDir();                
  OutputStreamWriter out;
  try {
      File f = new File(path.getCanonicalPath() + "/myfile.txt");
      out = new OutputStreamWriter(openFileOutput( f.getPath(), MODE_PRIVATE));
      out.write("test");
      out.close();                    
      }
  </code></pre>