Android将文件保存到内存时,出现问题
我试图将变量保存到一个文件中,似乎保存过程很好,但它找不到我保存的字符串。有人能帮我吗Android将文件保存到内存时,出现问题,android,save,Android,Save,我试图将变量保存到一个文件中,似乎保存过程很好,但它找不到我保存的字符串。有人能帮我吗 EditText Strength; String getstrengthvalue; String filename = "file.txt"; public void onSave(View view) { String string = "Hello world!"; FileOutputStream outputStream; try { outputSt
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();
}
}
openFileInput(文件名)代码>。应该是InputStream is=openFileInput(filename)代码>。然后从流is
读取。我需要将read和is命令放在哪里,以及如何使用它们。谢谢这里是您要从打开的流中读取的位置。只需与编写之前使用的write()
进行比较即可。还有谷歌,仍然不工作。。。不过还是要谢谢你!你根本没用谷歌搜索过是吗<代码>openFileInput(文件名)代码>。应该是InputStream is=openFileInput(filename)代码>。然后从流is
读取。我需要将read和is命令放在哪里,以及如何使用它们。谢谢这里是您要从打开的流中读取的位置。只需与编写之前使用的write()
进行比较即可。还有谷歌,仍然不工作。。。不过还是要谢谢你!你根本没用谷歌搜索过是吗?