Guest User

Untitled

a guest
Aug 1st, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. How to load FileInputStream in a septate class
  2. EditText eTuser;
  3. EditText eTpassword;
  4. CheckBox StaySignedIn;
  5. Button bSubmit;
  6. String user;
  7. String pass;
  8. FileOutputStream fos;
  9. FileInputStream fis = null;
  10. String FILENAME = "userandpass";
  11.  
  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. // TODO Auto-generated method stub
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.login);
  17. eTuser = (EditText) findViewById(R.id.eTuser);
  18. eTpassword = (EditText) findViewById(R.id.eTpassword);
  19. StaySignedIn = (CheckBox) findViewById(R.id.Cbstay);
  20. bSubmit = (Button) findViewById(R.id.bLogIn);
  21. bSubmit.setOnClickListener(this);
  22. File file = getBaseContext().getFileStreamPath(FILENAME);
  23. if (file.exists()) {
  24. Intent i = new Intent(LogIn.this, ChatService.class);
  25. startActivity(i);
  26. }
  27. //if if file exist close bracket
  28. try {
  29. fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
  30. fos.close();
  31. } catch (FileNotFoundException e) {
  32. // TODO Auto-generated catch block
  33. e.printStackTrace();
  34. } // end of catch bracket
  35. catch (IOException e) {
  36. // TODO Auto-generated catch block
  37. e.printStackTrace();
  38. } // end of catch
  39.  
  40. } // create ends here
  41.  
  42. public void onClick(View v) {
  43. // TODO Auto-generated method stub
  44. switch (v.getId()) {
  45.  
  46. case R.id.bLogIn:
  47. String user = eTuser.getText().toString();
  48. String pass = eTpassword.getText().toString();
  49. Bundle userandpass = new Bundle();
  50. userandpass.putString("user", user);
  51. userandpass.putString("pass", pass);
  52. Intent login = new Intent(LogIn.this, logincheck.class);
  53. login.putExtra("pass", user);
  54. login.putExtra("user", pass);
  55. startActivity(login);
  56.  
  57. if(StaySignedIn.isChecked());
  58. String userstaysignedin = eTuser.getText().toString();
  59. String passstaysignedin = eTpassword.getText().toString();
  60. try {
  61. fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
  62. fos.write(userstaysignedin.getBytes());
  63. fos.write(passstaysignedin.getBytes());
  64. fos.close();
  65. } catch(IOException e) {
  66. // end of try bracket, before the Catch IOExceptions e.
  67. e.printStackTrace();
  68.  
  69.  
  70.  
  71.  
  72. } // end of catch bracket
  73.  
  74.  
  75. } // switch and case ends here
  76. }// Click ends here
  77.  
  78. }// main class ends here
  79.  
  80. fis = openFileInput(FILENAME);
  81. byte[] dataArray = new byte[fis.available()];
  82. while (fis.read(dataArray) != -1); {
  83. //while statement }
Add Comment
Please, Sign In to add comment