daily pastebin goal
32%
SHARE
TWEET

Untitled

a guest Oct 23rd, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  public void onClick(View v) {
  2.         if (v.getId()==R.id.loadDataId){
  3.  
  4.             try {
  5.                 FileInputStream fileInputStream = openFileInput("Mydata.txt");
  6.                 StringBuffer buffer = new StringBuffer();
  7.                 int read = -1;
  8.                 while ((read =fileInputStream.read())!=-1){
  9.                     buffer.append((char) read);
  10.                 }
  11.                 //get user name by indet of string
  12.                 String userName =buffer.substring(0,buffer.indexOf(" "));
  13.                 String userPass = buffer.substring(buffer.indexOf(" ")+1);
  14.  
  15.                 unamrTextView.setText(userName);
  16.                 passTextView.setText(userPass);
  17.  
  18.             } catch (FileNotFoundException e) {
  19.                 e.printStackTrace();
  20.             } catch (IOException e) {
  21.                 e.printStackTrace();
  22.             }
  23.  
  24.  
  25.             Toast.makeText(this, "Data retrive successfully", Toast.LENGTH_SHORT).show();
  26.             }else if (v.getId()==R.id.gotoBackId){
  27.  
  28.             Intent intent = new Intent(SecondActivity.this,MainActivity.class);
  29.             startActivity(intent);
  30.             Toast.makeText(this, "Go to Main Activity", Toast.LENGTH_SHORT).show();
  31.         }
  32.  
  33.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top