Android 上的文件名允许使用哪些字符?
Android 上的文件名允许使用哪些特殊字符?
~!@#$%^&*()_+/\.,
另外,我可以用 Unicode 名称保存文件吗?
What special characters are allowed for file names on Android?
~!@#$%^&*()_+/\.,
Also, can I save file with Unicode name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
在 Android 上(至少默认情况下),文件名编码为 UTF-8。
看起来保留的文件名字符取决于安装的文件系统(http://en.wikipedia.org/wiki /Filename)。
我认为保留:
On Android (at least by default) the file names encoded as UTF-8.
Looks like reserved file name characters depend on filesystem mounted (http://en.wikipedia.org/wiki/Filename).
I considered as reserved:
来自 android.os.FileUtils
注意:FileUtils 是隐藏的 API(不适用于应用程序;适用于 AOSP 使用)。用作参考(或通过反思,风险自负)
From android.os.FileUtils
Note: FileUtils are hidden APIs (not for apps; for AOSP usage). Use as a reference (or by reflection at one's own risk)
根据 wiki 并假设您使用的是 FAT32 的外部数据存储。
是
According to wiki and assuming that you are using external data storage which has FAT32.
are
这是 Android 中文件名的正确 InputFilter:
This is correct InputFilter for File Names in Android:
这显然取决于文件系统和 Android 操作系统。 唯一字符
在我的 oneplus/oxygenOS 上,接受的答案中我无法用来重命名文件的
是 / 和 *但是,在 Android 范围内,上面的列表似乎是合理的。
This is clearly filesystem and Android operating system dependent. On my oneplus/oxygenOS, the only characters in the accepted answer
that I could not use to rename a file were / and *
However, Android wide, the list above would seem to be sensible.
我在 Android 上的 Galaxy Note 8 上快速进行了测试4.4.2.默认的“我的文件”应用程序会有效地将无效字符显示为灰色,如下所示:
? : " * | / \ <>
我将所有其他可用的特殊字符放入文件名中并保存。这在所有 Android 版本中可能不一致,因此最好保守一点,并将它们替换为类似有意义的字符。
I tested this quickly on my Galaxy Note 8 on Android 4.4.2. The default My Files app helpfully greys out invalid characters which are as follows:
? : " * | / \ < >
I put all the other special chars available into a filename and it saved. This may not be consistent across all Android versions so maybe it's best to be conservative and replace them with similarly meaningful characters.
在 Android 上按照建议,您可以使用输入过滤器来防止用户输入无效字符,这里是一个更好的实现:
On Android as suggested there you can use an input filter to prevent user entering invalid characters, here is a better implementation of it:
在 Android 中,标准键盘上出现的每个符号都是允许的
In Android every single symbol that appears on a standard keyboard is allowed ???????????????????????? ???????????? ????????????: the forward slash (" / ").
That means that the following five symbols, in particular, all of which are ????????????allowed in Windows...
* ? " : \
..are allowed to be used in Android filenames. Only the forward slash will generate an error.
That said, it's not impossible that certain Android apps may balk at opening/saving files whose names contain some of the allowed symbols.