得到java.io.FileNotFoundException时,应用程序卸载 - 再次构建>



我试图将数据保存到TXT文件,并在打开应用程序时再次读取,这是我使用的方法:

public static void saveFcmListString(String data,Context context) {
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("fcmConfig.txt", Context.MODE_PRIVATE));
outputStreamWriter.write(data);
outputStreamWriter.close();
}
catch (IOException e) {
Log.e("Exception", "saveFcmListString File write failed: " + e.toString());
}
}
public static String getFcmListString(Context context) {
String ret = "";
try {
InputStream inputStream = context.openFileInput("fcmConfig.txt");
if (inputStream != null ) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String receiveString = "";
StringBuilder stringBuilder = new StringBuilder();
while ( (receiveString = bufferedReader.readLine()) != null ) {
stringBuilder.append(receiveString);
//                    stringBuilder.append("n").append(receiveString);
}
inputStream.close();
ret = stringBuilder.toString();
}
}
catch (FileNotFoundException e) {
Log.e("login activity", "File not found: " + e.toString());
} catch (IOException e) {
Log.e("login activity", "Can not read file: " + e.toString());
}
return ret;
}

使用上述方法,我有fcmConfig文件,其中包含一些字符串,但当卸载+安装应用程序再次,我试图写入文件,但我得到了这个错误

File not found: java.io.FileNotFoundException: /data/user/0/.../files/fcmConfig.txt: open failed: ENOENT (No such file or directory)

我读文件,但不能确定文件被删除后卸载应用程序?

是,当应用程序被卸载时,存储在/data目录下的文件也被删除

最新的Android版本防止在卸载应用程序时留下任何数据

当你卸载你的应用程序时,你所有的应用程序的私有文件也会被删除。

保存在不同的地方,以便重新安装。

最新更新