Hi I'm having a problem while making an app on Android Studio. I want the user to input some text and then click the save button, which should save the text file on my phone. I have the following code running without any errors, however it is not doing anything. I cant find the file that it is supposed to save in.
public class TakeNotes extends Activity implements View.OnClickListener {
String content = "";
File file;
FileOutputStream outputStream;
TextView tv;
Button btnSave;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.take_notes);
tv = (TextView) findViewById(R.id.txtInput);
btnSave = (Button) findViewById(R.id.btnSave);
btnSave.setOnClickListener(this);
}
public void onClick(View v) {
if (v == findViewById(R.id.btnSave)) {
try {
file = new File(Environment.getExternalStorageDirectory(), "test.txt");
outputStream = new FileOutputStream(file);
outputStream.write(content.getBytes());
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}