Created
February 9, 2018 02:36
-
-
Save tuttelikz/eb0feca5d646481debddebd5534aa9ab to your computer and use it in GitHub Desktop.
this is a function to save strings to internal storage in android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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