我正在尝试将变量保存在文件中,似乎保存过程很好,但是找不到我保存的字符串。任何人都可以帮助我吗?
EditText Strength;
String getstrengthvalue;
String filename = "file.txt";
public void onSave(View view) {
String string = "Hello world!";
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(getstrengthvalue.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void onLoad(View view) {
try {
InputStream is = openFileInput(filename);
is.read(getstrengthvalue.getBytes());
Strength.setText(getstrengthvalue);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}