i created a file and when i run the program, the data is been written in to the file but when i run the program again the new data over write on old data. i need once the program is running and gathers data, these data are writable into the file in cascade next each other without overwriting on previous data in file.
this code running successful but when i run the program again the over writing happens which i don need that, i need to save previous data in side the file and write the new data next it and soon.
public class MainActivity extends Activity {
File file;
String sdCard;
FileOutputStream fos;
OutputStreamWriter myOutWriter;
String FlieName = "Output1.txt";
EditText txtData;
Button btnWriteSDFile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtData = (EditText) findViewById(R.id.editText1);
btnWriteSDFile = (Button) findViewById(R.id.button1);
btnWriteSDFile.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try {
file = new File("/sdcard/Output1.txt");
file.createNewFile();
fos = new FileOutputStream(file);
String eol = System.getProperty("line.separator");
myOutWriter =new OutputStreamWriter(fos);
myOutWriter.append(txtData.getText() + eol);// write from editor
myOutWriter.close();
fos.close();
Toast.makeText(v.getContext(),"Done writing SD 'Output.txt'", Toast.LENGTH_SHORT).show();
txtData.setText("");
} catch (Exception e) {
// e.printStackTrace();
Toast.makeText(v.getContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
});
}
}