title: How to send text from textview as text file(*.txt) with the help of a SEND intent ?(Android Application)
body: <p>I want to send whatever text is being currently displayed on the textview as a text file(.txt)  using a SEND intent so that the user may use bluetooth or attach it as an email to send the file.</p>
  
  <p>The function that I have written is :</p>
  
  <pre><code> public void send() throws IOException
      {
             myFile = new File(Environment.getExternalStorageDirectory().getPath()+"/"+programname+".txt");
             myFile.createNewFile();
             FileOutputStream fOut = new FileOutputStream(myFile);
             OutputStreamWriter myOutWriter =new OutputStreamWriter(fOut);
             myOutWriter.append(textView.getText());
             myOutWriter.close();
             fOut.close();
             Intent intent = new Intent();  
             intent.setAction(Intent.ACTION_SEND);  
             intent.setType("text/plain");
             intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(myFile) );  
             startActivity(intent);
             //myFile.delete();
             //Note that I have commented the last line to prevent file from being deleted
       }
  </code></pre>
  
  <p>What this code does is that it creates a new file,appends text from the textview to it and then this file is passed to ACTION_SEND intent which gives the user the option of sending this file via Bluetooth or send an email where the file gets attached automatically attached to gmail ,many other options, etc.</p>
  
  <p>It works as long as I don't call the delete function on the file(which causes the file to be deleted before it gets attached or is sent over Bluetooth).I want to be able to delete this file as it is unnecessarily taking up storage space.</p>
  
  <p>Please advise me as to what is the correct approach to solve this problem with a code sample if possible.</p>