title: How to save parsed text file in internal/external storage in android
body: <p>Currently I am working in project where I need to parse a remote text file and store it in local storage (internal/external). I am able to parse the text file but unable to store it in SDCARD. Here is my code :</p>
  
  <pre><code>package com.exercise.AndroidInternetTxt;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class AndroidInternetTxt extends Activity {
  
      TextView textMsg, textPrompt;
      final String textSource = "http://sites.google.com/site/androidersite"
                                                                + "/text.txt";
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          textPrompt = (TextView) findViewById(R.id.textprompt);
          textMsg = (TextView) findViewById(R.id.textmsg);
          textPrompt.setText("Wait...");
          URL textUrl;
          try {
              textUrl = new URL(textSource);
              BufferedReader bufferReader = new BufferedReader(
                      new InputStreamReader(textUrl.openStream()));
              String StringBuffer;
              String stringText = "";
              while ((StringBuffer = bufferReader.readLine()) != null) {
                  stringText += StringBuffer;
              }
              bufferReader.close();
              textMsg.setText(stringText);
              // Saving the parsed data.........
              File myFile = new File("sdcard/mysdfile.txt");
              if (!myFile.exists()) {
                  myFile.mkdirs();
              }
              myFile = new File("sdcard/mysdfile.txt");
              myFile.createNewFile();
              FileOutputStream fOut = new FileOutputStream(myFile);
              OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
              myOutWriter.append(textMsg.getText());
              myOutWriter.close();
              fOut.close();
              Toast.makeText(getBaseContext(), "Done writing SD 'mysdfile.txt'",
                  Toast.LENGTH_SHORT).show();
          } catch (MalformedURLException e) {
              e.printStackTrace();
              textMsg.setText(e.toString());
          } catch (IOException e) {
              e.printStackTrace();
              textMsg.setText(e.toString());
          }
          textPrompt.setText("Finished!");
      }
  }
  </code></pre>
  
  <p>And here is my manifest file - </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.exercise.AndroidInternetTxt"
        android:versionCode="1"
        android:versionName="1.0"&gt;
      &lt;uses-sdk android:minSdkVersion="4" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  
      &lt;application android:label="@string/app_name"&gt;
          &lt;activity android:name=".AndroidInternetTxt"
                    android:label="@string/app_name"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/&gt;
  &lt;/manifest&gt; 
  </code></pre>
  
  <p>However, My Question is - </p>
  
  <ul>
  <li>How do i Store the parsed text data in a file inside the SDCARD or Phone memory?</li>
  <li>There is any way to check the URL with pre-defined interval using timer?</li>
  </ul>
  
  <p>Any code example is excellent for me.</p>