Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. public void onClick(View v) {
  2. if (v.getId()==R.id.saveId){
  3.  
  4. String userName = nameEditText.getText().toString();
  5. String userPass = passEditText.getText().toString();
  6. userName = userName+" ";
  7.  
  8. File file = null;
  9. FileOutputStream fileOutputStream = null;
  10. try {
  11.  
  12. file = getFilesDir(); //for get file directory
  13. fileOutputStream = openFileOutput("Mydata.txt", Context.MODE_PRIVATE);
  14. fileOutputStream.write(userName.getBytes());
  15. fileOutputStream.write(userPass.getBytes());
  16.  
  17. } catch (FileNotFoundException e) {
  18. e.printStackTrace();
  19. } catch (IOException e) {
  20. e.printStackTrace();
  21. }finally {
  22. try {
  23. fileOutputStream.close();
  24. } catch (IOException e) {
  25. e.printStackTrace();
  26. }
  27. }
  28.  
  29.  
  30. Toast.makeText(this, "Data Save Successfully"+file+" /Mydata.txt", Toast.LENGTH_SHORT).show();
  31. }else if (v.getId()==R.id.secondId){
  32. Intent intent = new Intent(MainActivity.this,SecondActivity.class);
  33. startActivity(intent);
  34. Toast.makeText(this, "Next Activity", Toast.LENGTH_SHORT).show();
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement