【问题标题】:DocumentFile : problems creating specific directory nameDocumentFile:创建特定目录名称的问题
【发布时间】:2017-07-20 19:28:12
【问题描述】:

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

我无法创建名为“R.E.M.”(不带引号)的目录。

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

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");

这将显示“成功”,所以我很高兴。后来我想在这个目录下创建一个文件:“R.E.M./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");

这将显示“失败:R.E.M. 不存在

所以我使用 DocumentFile.listFiles 列出文件并查看:“R.E.M”(最后一个 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 限制的文档?

谢谢:)

【问题讨论】:

  • 限制取决于存储提供商。我不知道有任何存储提供商记录了它将接受和不接受的内容。

标签: android android-sdcard documentfile


【解决方案1】:

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

【讨论】: