Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Data saving and reading of memory card

Shulou Source: shulou.com Published: 2022-06-03 04:44:05 10月02日 Update

memory card

2.1 data save

File file=new File(Environment.getExternalStorageDirectory(), name);

try {

FileOutputStream fos=new FileOutputStream(file);

fos.write(content.getBytes());

fos.close();

Toast.makeText(getApplicationContext(), "Save successfully", 200).show();

} catch (Exception e) {

Toast.makeText(getApplicationContext(), "Save Failed", 200).show();

e.printStackTrace();

}

2.2 data read

File file=new File(Environment.getExternalStorageDirectory(), name);

try {

FileOutputStream fos=new FileOutputStream(file);

fos.write(content.getBytes());

fos.close();

Toast.makeText(getApplicationContext(), "Save successfully", 200).show();

} catch (Exception e) {

Toast.makeText(getApplicationContext(), "Save Failed", 200).show();

e.printStackTrace();

}

3,sharedprefrence (****)

btn_ok.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

String user = et_user.getText().toString().trim();

String pwd = et_pwd.getText().toString().trim();

if(user.isEmpty()||pwd.isEmpty()){

Toast.makeText(getApplicationContext(), "cannot be empty", 200).show();

//Get Editor

Editor edit = sp.edit();

//Save data

edit.putString("name", user);

edit.putString("pwd", pwd);

//submit save

edit.commit();

}

}

});

Tags: Data success memory memory Card Editor Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn Xiaomi Apple Microsoft