【问题标题】:android data save directoriesandroid数据保存目录
【发布时间】:2013-01-22 10:17:55
【问题描述】:

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

当我使用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

我的应用程序的前端是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/ 创建文件夹吗?

【问题讨论】:

    标签: android filesystems directory


    【解决方案1】:

    简单的方法,您可以根据许多条件更改此代码。如果您知道您的路径与 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();
    

    两个代码都有效。

    工作证明:

    【讨论】:

      猜你喜欢
      • 2016-11-17
      • 2015-07-04
      • 1970-01-01
      • 2012-09-10
      • 2016-10-09
      • 2012-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多