level 1
MainActivity的代码:
package com.example.administrator.app0502;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
private EditText username;
private EditText password;
private Button login;
String strName;
String strPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username=(EditText)findViewById(R.id.et_username);
password=(EditText)findViewById(R.id.et_psaaword);
login=(Button)findViewById(R.id.but_login);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
strName=username.getText().toString();
strPassword=password.getText().toString();
FileOutputStream fos=null;
try{
fos=openFileOutput("LOGIN",MODE_PRIVATE);
fos.write((strName+""+strPassword).getBytes());
fos.flush();
}catch (FileNotFoundException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}finally {
if (fos!=null){
try{
fos.close();
}catch (IOException e){
e.printStackTrace();
}
}
}
Intent intent=new Intent();
intent.setClass(MainActivity.this,ReadActivity.class);
startActivity(intent);
}
});
}
}
2017年04月22日 06点04分