You need to append to the file. You are overwriting the file. This is
standard Java I/O and has nothing in particular to do with Android.
http://exampledepot.com/egs/java.io/AppendToFile.html
On Sun, Oct 30, 2011 at 4:54 PM, leigh8347 wrote:
> hello
>
> can anyone help?
>
> on my app im trying to do the following - Save 2 user inputs to a .txt
> file and save it, then be able to enter 2 more inputs and save again
> and repeat many times.
>
> so far my code creates a file, writes the first 2 inputs and saves.
> but when i try saving another 2 it just replaces the first. im quite
> confused.
>
> here is what i have
>
> txtData = (EditText) findViewById(R.id.input1);
> txtData2 = (EditText) findViewById(R.id.input2);
>
> btnWriteSDFile = (Button) findViewById(R.id.save);
> btnWriteSDFile.setOnClickListener(new OnClickListener() {
>
> public void onClick(View v) {
> // write on SD card file data in the text box
> try {
> File myFile = new
> File(Environment.getExternalStorageDirectory(),
> "parkrun_barcode.txt");
> myFile.createNewFile();
> FileOutputStream fOut = new FileOutputStream(myFile);
> OutputStreamWriter myOutWriter = new
> OutputStreamWriter(fOut);
>
> myOutWriter.append(txtData.getText() + ", " +
> txtData2.getText());
> myOutWriter.close();
> fOut.close();
> Toast.makeText(getBaseContext(),
> "Saved'",
> Toast.LENGTH_SHORT).show();
> } catch (Exception e) {
> Toast.makeText(getBaseContext(), e.getMessage(),
> Toast.LENGTH_SHORT).show();
> }
>
> txtData.setText("");
> txtData2.setText("");
>
>
> }
> });
>
> }
>
> }
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy
Android Training in NYC: http://marakana.com/training/android/
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en