0

我有一个应用程序必须在可移动 sdcard 上创建文件和目录。我使用DocumentFile API。在大多数情况下,它可以工作:) 但我发现一个案例不起作用(至少在三星 GS7 上):

我无法创建名为“ REM ”(不带引号)的目录。

测试用例:我在目录“/storage/9C33-6BBD/Xxxx”中工作,我想创建目录“REM”

DocumentFile parentDf;
// init of parentDf to point to /storage/9C33-6BBD/Xxxx
DocumentFile remDf = df.createDirectory("R.E.M.");
if(remDf == null)
    displayMessage("failure");
else
    displayMessage("success");

这将显示“成功”,所以我很高兴。后来我想在这个目录中创建一个文件:“REM/myfile”。

DocumentFile parentDf;
// init of parentDf to point to /storage/9C33-6BBD/Xxxx
DocumentFile remDf = parentDf.findFile("R.E.M.");
if(remDf == null) {
    displayMessage("failure : R.E.M. doesn't exists");
    return false;
}

DocumentFile myfileDf = remDf.createFile("text/plain","myfile");
if(remDf == null)
    displayMessage("failure");
else
    displayMessage("success");

这将显示“失败:REM 不存在

所以我用 DocumentFile.listFiles 列出文件并查看:“REM”(最后一个 DOT 消失了!

如果我这样做(new File("/storage/9C33-6BBD/Xxxx/R.E.M.")).exists(),它会返回 true !

如果我看一下“adb shell”

hero2lte:/storage/9C33-6BBD/Xxxx $ ls -la                                                                                                       
total 768
drwxrwx--x  3 root sdcard_rw 131072 2017-07-19 14:18 .
drwxrwx--x 17 root sdcard_rw 131072 2017-07-19 13:31 ..
drwxrwx--x  2 root sdcard_rw 131072 2017-07-19 13:46 R.E.M

hero2lte:/storage/9C33-6BBD/Xxxx $ ls -lad R.E.M.                                                                                               
drwxrwx--x 2 root sdcard_rw 131072 2017-07-19 13:46 R.E.M.

有谁知道我在哪里可以找到有关目录 displayName 限制的文档?

谢谢 :)

4

1 回答 1

1

实际上,这不是 DocumentFile API 限制,而只是文件系统限制:Microsoft 文件系统(至少 VFAT 和 NTFS)不支持以点 (.) 结尾的目录名称。

于 2017-07-20T11:28:12.637 回答