2010-04-21 44 views

回答

29
  1. 在Android上(至少默認情況下)編碼爲UTF-8的文件名。

  2. 看起來像保留的文件名字符取決於掛載的文件系統(http://en.wikipedia.org/wiki/Filename)。

我認爲是保留:

private static final String ReservedChars = "|\\?*<\":>+[]/'"; 
+7

'+ []不保留 – xmen 2015-01-04 09:01:53

+0

https://superuser.com/a/693819/687273 – 2017-07-23 11:25:51

4
final String[] ReservedChars = {"|", "\\", "?", "*", "<", "\"", ":", ">"}; 

for(String c :ReservedChars){ 
    System.out.println(dd.indexOf(c)); 
    dd.indexOf(c); 
} 
8

根據wiki並且假設使用的是外部數據存儲具有FAT32。在目錄

容許字符的條目

任何字節除了值0-31,127(DEL)和:「* /?:<> \ | +, 。; = [](低字母az存儲爲AZ)。使用VFAT LFN除NUL以外的任何Unicode

+1

「;,。=」允許在android中的文件名 – Shaegorath 2014-08-09 13:02:00

+0

在外部和內部存儲上都是如此嗎?剩下的所有角色都允許嗎?做lowercard =大寫,因爲文本顯示在這裏(意思是我不能在同一個文件夾上有「Hello.txt」和「hello.txt」)? – 2015-04-20 23:33:52

0

我在Android 4.4.2上的3210。默認的「我的文件」應用程序可幫助灰顯無效字符,如下所示:

? :「* |/\ <>

我把所有可用的其他特殊字符都放到一個文件名中,並保存下來,這可能在所有Android版本中都不一致,所以最好保守一些,用相似的有意義的字符替換它們。

+0

什麼是Galaxy Note 8?特別是在2014年。 – 2016-06-01 02:59:42

+0

從三星網站:[Note Tablet](http://www.samsung.com/us/business/support/owners/product/GT-N5110ZWYXAR) – TopherC 2016-06-05 17:29:29

3

這是正確的輸入過濾在Android文件名:

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; 
     } 
    }; 
0

這顯然是公認的答案

文件系統和Android操作系統的依賴於我的萬普拉斯/ oxygenOS,唯一的字符。
private static final String ReservedChars = "|\\?*<\":>+[]/'"; 

,我不能用它來重命名文件是/和*

不過,Android寬,上面的列表中似乎是合理的。

相關問題