Reputation: 450
I am trying to save a string input from the user (called editServer) into a internal file with:
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
EditText server = (EditText) findViewById(R.id.editServer);
Log.i("Settings", server.getText().toString());
String filename = "ServerURL.txt";
String serverurl = server.getText().toString();
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(serverurl.getBytes());
Log.i("Write",serverurl+" saved to "+filename);
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
My issue is that after that I can't find this file. Where is it? I tried opening the Android Device Monitor with Android Studio but I can't find the folder. I tried to get the string using:
fis = context.openFileInput("ServerURL.txt");
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader bufferedReader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
}
return line;
But it returns null, which makes me believe that I am making a mistake. Am I creating the file properly or is there some issue in my code?
Thank you.
Update
Android device monitor -> File explorer will let you see and find where your file is.
Upvotes: 0
Views: 63