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

What's the file path of context.openFileOutput()

我想知道使用 context.openFileOutput() 将我的文件写入(在存储中)的实际路径,如下所示(跳过例外)。

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() 来查看该目录中有哪些文件。然后您需要确定哪些文件代表您的对象(相对于该目录中的其他文件),并计算这些文件。

首先,我想让你明白一些事情:

getFilesDir() returns 一个文件对象,您可以从中获取 path/location.

正在调用 getFilesDir().listFiles() returns 您使用 openFileInput()openFileInput().

保存的所有文件的数组

根据上面的解释,您的文件都位于getFilesDir()路径中。