Validate a file name on Windows

后端 未结 11 1973
一生所求
一生所求 2020-11-29 23:28
public static boolean isValidName(String text)
{
    Pattern pattern = Pattern.compile(\"^[^/./\\\\:*?\\\"<>|]+$\");
    Matcher matcher = pattern.matcher(text         


        
11条回答
  •  醉梦人生
    2020-11-30 00:06

    Here you can find which file names are allowed.

    The following characters are not allowed:

    • < (less than)
    • (greater than)

    • : (colon)
    • " (double quote)
    • / (forward slash)
    • \ (backslash)
    • | (vertical bar or pipe)
    • ? (question mark)
    • * (asterisk)

    • Integer value zero, sometimes referred to as the ASCII NUL character.

    • Characters whose integer representations are in the range from 1 through 31, except for alternate data streams where these characters are allowed. For more information about file streams, see File Streams.
    • Any other character that the target file system does not allow.

提交回复
热议问题