1

我的应用程序主要是 c++(使用 NDK),所以我使用fopen,fwrite等标准函数来创建和游戏保存文件并写入它们。

当我使用fopen("game.sav", "wb")时,它似乎是在路径创建的

/data/user/10/com.my.game/files/game.sav.

我的应用程序是多用户的。所以我想要一个单独的文件夹,用户可以在其中存储他们的保存文件。而不是上面的路径,我想要像这样的路径

/data/user/10/com.my.game/files/user0/game.sav,

/data/user/10/com.my.game/files/user1/game.sav, ETC

我的应用程序的前端是 Java,当注册新用户时,我想创建一个文件夹/data/user/10/com.my.game/files/user0/。但我不知道该怎么做,因为

final File newDir = context.getDir("user0", Context.MODE_PRIVATE);

导致在/data/user/10/com.my.game/app_user0不同的路径上创建路径。

可以在/data/user/10/com.my.game/files/以及如何创建文件夹?

4

1 回答 1

3

简单的方法,这个代码你可以改变它以适应许多条件。如果您知道您的路径与 getFilesDir() 获取的路径不同,那么您可以首先使用您知道的路径创建一个文件,最后两行代码仍然相同。

    File file = this.getFilesDir(); // this will get you internal directory path
    Log.d("BLA BLA", file.getAbsolutePath());
    File newfile = new File(file.getAbsolutePath() + "/foo"); // foo is the directory 2 create
    newfile.mkdir();

如果您知道“文件”目录的路径:

     File newfile2 = new File("/data/data/com.example.stackoverflow/files" + "/foo2");
    newfile2.mkdir();

两种代码都有效。

工作证明:

工作证明:

于 2013-01-22T10:46:24.423 回答