title: Writing to the internal private storage in Android
body: <p>I am trying to save some data from my app in a simple text file on the internal private storage area (app user preferences). I have read through many questions on here (StackOverflow) and tried the solutions suggested with no success. The simplest solution, it seems, would be the one suggested here:<br /><br />  <a href="http://developer.android.com/guide/topics/data/data-storage.html#filesInternal" rel="noreferrer">http://developer.android.com/guide/topics/data/data-storage.html#filesInternal</a> <br /><br />but I cannot get this to work on my test device. I have also tried to create the file using the methods available in the java.io.File with the appropriate methods. I have also tried to create the file on the SDCard with the same result, fail. I have tried many solutions listed in other answers, following the code and instructions suggested exactly and find the same result. I am beginning to feel that I am missing some important bit of code, or a setting flag somewhere, I have set the permission in the manifest file:
  <br /><br />  </p>
  
  <pre><code>  &lt;uses-permission 
          android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p><br />  </p>
  
  <p>To be clear, I am trying to write to the device's internal, private storage. It is a small file containing a name, phone number, and a couple of type <code>int</code> flags. What ever method I use, I either find that the file did not create (or change if I place the file manually on the SDCard), or I get a NullPointerException when I try to reference the file or file location:
  <br /></p>
  
  <pre><code>private              File   fILE = new File("Mydata", main.FILENAME);
  </code></pre>
  
  <p>or<br /></p>
  
  <pre><code>private              File   fILE  = getDir("Mydata", 0);
  </code></pre>
  
  <p><br />
  I am running the code on a HTC Hero, updated with the latest service release from Sprint. Any help would be GREATLY appreciated, Thanks in advance!</p>
  
  <p>-Steve</p>
  
  <p>Update (2/2/11): Using a EVO (API 8) I still get a NullPointerException. The code generating the exception is below, any thoughts on why my app can't access the internal storage? I have this problem on three different physical devices using two API levels (API 7 and 8).</p>
  
  <pre><code>    File newfile = new File(this.getFilesDir() + "/data/files/", "sample.txt");
  </code></pre>
  
  <p>UPDATE 2: 2/4/11 - I have found that I cannot see the file structure on the physical device (data directory) under any circumstance. Any one have any thoughts on this? The device is properly configured and can run app from eclipse or adb.</p>
  
  <p>UPDATE 3: (2/9/11) - I think I may have found what the problem is here, but I am not sure about how to deal with it. I have figured out that the permissions on the /data/ directory on the physical devices are: <code>drwxrwx--x</code>. I am not sure why it is this way, maybe something to with Sprint? I have found this set this way on an HTC Hero, Samsung Epic (Galaxy S), and HTC EVO all on Sprint. The issue appears to be that DDMS and my app do not have r/w access to the directory. I need to figure out 2 things here, why it is like this and how to over come this issue in the wild. Again, any help here would be AWESOME!!</p>
  
  <p>UPDATE 4: I think last February was a total blonde moment for me (see UPDATE 3). The test devices that I have are not ROOTed and hence no access (DUH!). After all the updates that he SGS and the EVO 4G have gone through, the result is still the same. I am still working this problem and will try and get back here with an update soon (hopefully less than a year next time).</p>