Hii I am New to Android Development an i am trying this simple application and my issues is
I am Trying to save a block of data from Edit Text to a file on click of a Button
but I am unable to do so!
my Block of Code is
saveBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String str = textBox.getText().toString();
try
{
FileOutputStream fOut =
openFileOutput("textfile.txt", MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write();
osw.flush();
osw.close();
Toast.makeText(getBaseContext(), "File saved successfully!", Toast.LENGTH_SHORT).show();
Toast.makeText(getBaseContext(), "file path" + getFileStreamPath ("textfile.txt"), Toast.LENGTH_LONG).show();
textBox.setText("");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
You were unable to do so because you not passing the Str value
ie String str = textBox.getText().toString();
to:- osw.write();
Like I have Done
osw.write(str);
this will solve your problem I have Tested this
for more such resources, just have a look at the below site
http://www.suvenconsultants.com/