我想知道使用 context.openFileOutput()
写入文件的实际路径(在存储中),如下所示(跳过异常(exception))。
public static void writeObject(Context context, String name, Object object){
FileOutputStream fos = context.openFileOutput(name, Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object);
oos.close();
fos.close();
}
最佳答案
How can I get the exact path
您正在使用openFileInput()
和openFileOutput()
。这些文件存储在由 getFilesDir()
标识的位置。
also the total number of objects saved in that path/directory?
嗯,看起来每个文件只存储一个对象。您可以对 getFilesDir()
返回的 File
对象使用 listFiles()
来查看该目录中有哪些文件。然后,您需要确定哪些文件代表您的对象(相对于该目录中的其他文件),并对这些文件进行计数。
关于java - context.openFileOutput() 的文件路径是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46136079/