Android 上的文件名中允许使用哪些字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2679699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What characters allowed in file names on Android?
提问by alex2k8
What special characters are allowed for file names on Android?
Android 上的文件名允许使用哪些特殊字符?
~!@#$%^&*()_+/\.,
Also, can I save file with Unicode name?
另外,我可以用Unicode名称保存文件吗?
采纳答案by alex2k8
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).
在 Android 上(至少在默认情况下)文件名编码为 UTF-8。
看起来保留的文件名字符取决于安装的文件系统(http://en.wikipedia.org/wiki/Filename)。
I considered as reserved:
我认为是保留的:
private static final String ReservedChars = "|\?*<\":>+[]/'";
回答by kreker
According to wikiand assuming that you are using external data storage which has FAT32.
根据wiki并假设您使用的是具有 FAT32 的外部数据存储。
Allowable characters in directory entries
目录条目中允许的字符
are
是
Any byte except for values 0-31, 127 (DEL) and: " * / : < > ? \ | + , . ; = [] (lowcase a-z are stored as A-Z). With VFAT LFN any Unicode except NUL
除了值 0-31, 127 (DEL) 和:" * / : < > ? \ | + , . ; = [](小写 az 存储为 AZ)之外的任何字节。使用 VFAT LFN 除 NUL 之外的任何 Unicode
回答by Blackbern
final String[] ReservedChars = {"|", "\", "?", "*", "<", "\"", ":", ">"};
for(String c :ReservedChars){
System.out.println(dd.indexOf(c));
dd.indexOf(c);
}
回答by Quark
This is correct InputFilterfor File Names in Android:
这是Android 中文件名的正确InputFilter:
InputFilter filter = new InputFilter()
{
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
if (source.length() < 1) return null;
char last = source.charAt(source.length() - 1);
String reservedChars = "?:\"*|/\<>";
if(reservedChars.indexOf(last) > -1) return source.subSequence(0, source.length() - 1);
return null;
}
};
回答by TopherC
I tested this quickly on my Galaxy Note 8on Android 4.4.2. The default My Files app helpfully greys out invalid characters which are as follows:
我在 Android 4.4.2上的Galaxy Note 8上进行了快速测试。默认的“我的文件”应用程序有助于将无效字符变灰,如下所示:
? : " * | / \ < >
? :" * | / \ < >
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 版本中可能不一致,因此最好保守一些并用类似的有意义的字符替换它们。
回答by marzetti
This is clearly filesystem and Android operating system dependent. On my oneplus/oxygenOS, the only characters in the accepted answer
这显然依赖于文件系统和 Android 操作系统。在我的 oneplus/oxygenOS 上,已接受答案中的唯一字符
private static final String ReservedChars = "|\?*<\":>+[]/'";
that I could not use to rename a file were / and *
我不能用来重命名文件的是 / 和 *
However, Android wide, the list above would seem to be sensible.
但是,在 Android 范围内,上面的列表似乎是明智的。