title: How to clear text file in Android-java
body: <p>I have text file in Android called "longlat.txt".</p>
  
  <p>The text file contain latitude and longitude.</p>
  
  <p>I save all the latitude and longitude to the text file using buffreader method.</p>
  
  <p>After I finished using this app, I want to exit the app.
  Means that I need to clear "longlat.txt" so that later on when I use the app, it will start the app without previous data that already being save to "longlat.txt".</p>
  
  <p>So I provide a button called "Clear data" to clear the text file.</p>
  
  <p>Now I need some ideas to clear "longlat.txt" file when user click "Clear data" button.</p>
  
  <p>The only method that I'd used to clear the text file is I need to uninstall the app from my phone and reinstall it again .</p>
  
  <p><strong>I have tried :</strong></p>
  
  <pre><code>public void Clear(View view){    
  
       PrintWriter writer;
      try {
          writer = new PrintWriter("longlat.txt");
           writer.print("");
           writer.close();
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  
       }
  </code></pre>
  
  <p>After I clicked it, I want to check whether the text file already clear or not with click "Update" button, but when I click "Update" button, it still shows the old text file.</p>