gpt4 book ai didi

java - Java、Android 上本地存储中的文件

转载 作者:行者123 更新时间:2023-11-30 09:45:05 25 4
gpt4 key购买 nike

我通过这种方式将对象序列化为本地存储中的新文件:

ObjectOutputStream output=new ObjectOutputStream(openFileOutput("settings.dat", Context.MODE_PRIVATE));
output.writeObject(this);
output.close();

但在另一个函数中我必须检查文件是否存在:

File file=new File("settings.dat");
if (file.exists()) Toast.makeText(this, "yes", Toast.LENGTH_LONG).show();

file.exists() 总是返回 false。请帮帮我。

最佳答案

使用:

File file = new File(getFilesDir() + "/settings.dat");

http://developer.android.com/reference/android/content/Context.html#getFilesDir%28%29

关于java - Java、Android 上本地存储中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7596764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com