Android将文件保存到内部存储器,出错了

时间:2016-11-09 16:08:31

标签: android save

我正在尝试将变量保存在文件中,似乎保存过程很好,但是找不到我保存的字符串。任何人都可以帮助我吗?

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();
    }
}

0 个答案:

没有答案