title: android StringBuilder to save as .txt file on sdcard
body: <p>I need help!
  can someone see my line of codes here. Currently im writing a code to save calllogs into a .txt file and save it to sdcard. It can run but not saving the stringbuilder variable to sdcard. Im new to android programming.    </p>
  
  <pre><code>package com.example.calllog;
  
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.OutputStreamWriter;
  import java.util.Date;
  
  import android.app.Activity;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.provider.CallLog;
  import android.widget.Switch;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Cursor mCursor = managedQuery(CallLog.Calls.CONTENT_URI, null, null,
                  null, null);
          int number = mCursor.getColumnIndex(CallLog.Calls.NUMBER);
          int date = mCursor.getColumnIndex(CallLog.Calls.DATE);
          int duration = mCursor.getColumnIndex(CallLog.Calls.DURATION);
          int type = mCursor.getColumnIndex(CallLog.Calls.TYPE);
          StringBuilder sb = new StringBuilder();
          while (mCursor.moveToNext()) {
              String phnumber = mCursor.getString(number);
              String callduration = mCursor.getString(duration);
              String calltype = mCursor.getString(type);
              String calldate = mCursor.getString(date);
              Date d = new Date(Long.valueOf(calldate));
              String callTypeStr = "";
              switch (Integer.parseInt(calltype)) {
              case CallLog.Calls.OUTGOING_TYPE:
                  callTypeStr = "Outgoing";
                  break;
              case CallLog.Calls.INCOMING_TYPE:
                  callTypeStr = "Incoming";
                  break;
              case CallLog.Calls.MISSED_TYPE:
                  callTypeStr = "Missed";
                  break;
              }
  
              sb.append("Phone number " + phnumber);
              sb.append(System.getProperty("line.separator"));
              sb.append("Call duration " + callduration);
              sb.append(System.getProperty("line.separator"));
              sb.append("Call type " + callTypeStr);
              sb.append(System.getProperty("line.separator"));
              sb.append("Call date " + d);
              sb.append("---------------------------");
              sb.append(System.getProperty("line.separator"));
  
          }
  
  
  
      try{
  
          File sdcard = new File("/mnt/extSdCard/");      
          File myFile = new File(sdcard.getAbsolutePath() + "/myForensicFile");
          myFile.mkdirs();
          File file = new File(myFile,"Call Logs.txt");
          FileOutputStream fOut = new FileOutputStream(file);
          OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
          myOutWriter.write(sb.toString());
          myOutWriter.close();
          Toast.makeText(getBaseContext(), "Call Logs Data saved to SDcard 'myForensicFile.txt'",Toast.LENGTH_LONG).show();
      }catch (Exception e){
          Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
      }
  
  }
  }
  </code></pre>