java - context.openFileOutput() 的文件路径是什么

标签 java android serialization storage

我想知道使用 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/

相关文章:

java - 验证 guice 模块配置 - 如何使用 SPI?

java - JNI 是提高位操作性能的解决方案吗?

java - JPA 父子有效。单独插入 child

java.security.spec.InvalidKeySpecException : java. lang.NoSuchMethodException:

c# - 序列化异常 : "Type\...\in assembly\...\is not marked as serializable" appears when I try to serialize ObservableCollection

android - 将 Serializable 对象写入外部存储时出现 java.io.NotSerializableException?

java - 用于连接超时和打开连接数的 Netty channel 配置

Android 深度链接和 App 链接混淆

android - id_token 缺少使用 AD FS 2016 使用 OpenID Connect 的自定义声明

c# - C#有解析多层级联JSON的库吗?