write in a file in one activity and read it in another activity
<p>I'm trying to write something in a file in one activity and after i try to read it in another activity to show it.
In fact, the user have to enter the recipient's number once. After that, i will enter this recipient's number for him automatically...</p>

<p>I don't know where is my error, i try since yesterday...
Thank you very much for your helps..</p>

<p>package com.example.automatik;</p>

<p>public class AddRecipientNumber extends Activity {</p>

<pre><code>//On stocke le n° du destinataire (1)
String FILENAME = "recipientnumber.txt";
String mehmet = "mehmetmehmet";
FileOutputStream fos;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_recipient_number);
    // Show the Up button in the action bar.
    setupActionBar();

    Button button = (Button)findViewById(R.id.recipientbutton1);
    button.setOnClickListener(new View.OnClickListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onClick(final View v)
        {
            EditText textA = (EditText)findViewById(R.id.recipientedit1);
            String a = textA.getText().toString();
            EditText textB = (EditText)findViewById(R.id.recipientedit2);
            String b = textB.getText().toString();

            if(a.equals(b))
            {
                //On stocke le n° du destinataire (2)
                try
                {
                    fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
                    fos.write(mehmet.getBytes());
                    fos.close();
                } 
                catch (FileNotFoundException e) { e.printStackTrace(); } 
                catch (IOException e) { e.printStackTrace(); }

                AlertDialog alertdialog = new AlertDialog.Builder(AddRecipientNumber.this).create();
                alertdialog.setMessage("You entered these numbers correctly.\nNow, we will move to the second step!");
                alertdialog.setButton("Move", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        sendMove(v);
                    }
                });
                alertdialog.show();
            }
            else
            {
                AlertDialog alertdialog = new AlertDialog.Builder(AddRecipientNumber.this).create();
                alertdialog.setMessage("These numbers must be identical. \nPlease try again.");
                alertdialog.show();
            } 
        }
    });
}

//Une fois que les numéros entrés sont identiques &amp; que l'utilisateur accepte de passer à la 2nde étape, on lance:
public void sendMove(View v)
{
    Intent intent = new Intent(this, AddMasterNumber.class);
    startActivity(intent);
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
</code></pre>

<p>}</p>

<p>and my second activity:</p>

<p>package com.example.automatik;</p>

<p>public class AddMasterNumber extends Activity {</p>

<pre><code>String finall;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_master_number);
    // Show the Up button in the action bar.
    //setupActionBar(); 

    //On récupère le n° du destinataire stocké
    try
    {
        FileInputStream in = openFileInput("recipientnumber.txt");
        StringBuffer fileContent = new StringBuffer("");

        byte[] buffer = new byte[1024];

        while(in.read(buffer) != -1)
        {
            fileContent.append(new String(buffer));
        }
        in.close();
        finall = fileContent.toString();
    }
    catch (FileNotFoundException e) { e.printStackTrace(); } 
    catch (IOException e) { e.printStackTrace(); }

    TextView text = (TextView)findViewById(R.id.recipienttext3);
    text.setText(finall);
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
</code></pre>

<p>}</p>
