Skip to content

Instantly share code, notes, and snippets.

@tuttelikz
Created February 9, 2018 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuttelikz/eb0feca5d646481debddebd5534aa9ab to your computer and use it in GitHub Desktop.
Save tuttelikz/eb0feca5d646481debddebd5534aa9ab to your computer and use it in GitHub Desktop.
this is a function to save strings to internal storage in android
public void save(View view) {
String text1 = username.getText().toString();
String text2 = password.getText().toString();
text1 = text1 + " ";
File file = null;
FileOutputStream fileOutputStream = null;
try {
file=getFilesDir();
fileOutputStream = openFileOutput("vivz.txt", Context.MODE_PRIVATE);
fileOutputStream.write(text1.getBytes());
fileOutputStream.write(text2.getBytes());
} catch (FileNotFoundException e) {
//e.printStackTrace();
Log.d("VIVZ",e.toString());
} catch (IOException e) {
e.printStackTrace();
}
finally {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Toast.makeText(this,"Saved successfully " +file+"/vivz.txt",Toast.LENGTH_SHORT).show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment