title: Environment.getExternalStorageDirectory().getAbsolutePath() gives a different path - Android
body: <p>I try to write something into my phone memory.</p>
  
  <p>At first, I hard-coded the path as:</p>
  
  <pre><code>myFile = new File("/sdcard/" + txtName.getText() + ".txt");
  </code></pre>
  
  <p>This works totally ok.</p>
  
  <p>And then, eclipse gives me a warning saying that I shouldn't have hard-coded the path like that instead, I should do the following:</p>
  
  <pre><code>myFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/"+ txtName.getText() + ".txt");
  </code></pre>
  
  <p>Then I follow the correction suggestion and avoid the warning.</p>
  
  <p>However, I encountered a runtime exception on the writer class.</p>
  
  <p>Then, I print out <code>Environment.getExternalStorageDirectory().getAbsolutePath()</code> for debugging purpose. The result is</p>
  
  <blockquote>
    <p>/storage/sdcard0</p>
  </blockquote>
  
  <p>. But the hardcoded one that worked perfectly fine before is actually </p>
  
  <blockquote>
    <p>/sdcard</p>
  </blockquote>
  
  <p>.</p>
  
  <p><strong>Why would this happen?</strong></p>
  
  <p><strong>And if I wish to avoid the warning, how can I get the path directory in a more "formal and right" way instead of hardcoding the path?</strong></p>
  
  <p>P.S.: My phone is HTC One X, which has NO external SD card slot. I guess the 32GB storage comes with a built-in SD card, and therefore, the essence should be the same.</p>