title: Deleting Strings from text file Android - File IO
body: <p>I would like to delete a string from a text file. I have seen that I need a temp file to do this with.  I would like to read from a list.txt file and delete a string in it.  The file I wish to search through has already been created and populated  I have seen other posts on this and am trying to modify it to my own personal project.  Currently I have:</p>
  
  <pre><code>        package com.nullwall.listmanager;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.io.IOException;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.os.Environment;
  
  public class IPR3Activity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          DoWork("TestString");
      }
  
  
  public void DoWork(String deleteFromFile)
  {
      try{
      String delete = deleteFromFile;
      String line;
  
      //locates a new file named list.txt
      File root = new File(Environment.getExternalStorageDirectory(),"projects");
      File file = new File(root, "list.txt");
  
      //creates buffers
      BufferedReader bufferedReader = new BufferedReader(new FileReader(file.getAbsolutePath()));
      StringBuffer stringBuffer = new StringBuffer();
  
      //Loads list.txt into bufferedReader, deletes line and moves on
      while ((line = bufferedReader.readLine()) != null)
      {
          if (line.equals(deleteFromFile))
          {
          line.replace(deleteFromFile, "");
          stringBuffer.append("\n");      
          }
          else 
          {
          stringBuffer.append(line);
          stringBuffer.append("\n");
          }
      }
      //Entire file has now been loaded into memory
  
      //creates new Filewriter, append to false, rewrites list.txt with stringBuffer minus string
      FileWriter writer = new FileWriter(file, false);
      writer.write(stringBuffer.toString());
      System.out.println("file written");
  
      //closes writer
      writer.flush();
      writer.close();
  
  
      }
      catch (FileNotFoundException ex) {
          ex.printStackTrace();
        }
        catch (IOException ex) {
          ex.printStackTrace();
        }
  
  }
  
  
  }
  </code></pre>
  
  <p>I have list.txt with random strings like this :</p>
  
  <pre><code>notstring
  notstring
  notstring
  teststring 
  notstring 
  notstring
  </code></pre>
  
  <p>After running, nothing happens.  I am fairly new to doing File IO like this so please don't overlook simple things I may have missed.  Thank you!</p>