Любые эксперты, которые могут мне помочь? В моей основной деятельности Android я пытаюсь сохранить String в файл, а затем получить его, если пользователь установил его раньше. Не удалось найти каких-либо примеров, близких к тому, что я делаю. Я бы очень признателен за любую помощь! Вот мой тестовый пример:
String testString = "WORKS";
String readString;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FileOutputStream fos;
try {
fos = openFileOutput("test.txt", Context.MODE_PRIVATE);
fos.write(testString.getBytes());
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
File file = getBaseContext().getFileStreamPath("test.txt");
if (file.exists()) {
FileInputStream fis;
try {
fis = openFileInput("test.txt");
fis.read(readString.getBytes());
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
txtDate.setText(String.valueOf(readString));
} else {
// more code
}
}
}