Validate a file name on Windows

后端 未结 11 2063
一生所求
一生所求 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:22

    How about letting the File class do your validation?

    public static boolean isValidName(String text) {
        try {
            File file = new File(text);
            return file.getPath().equals(text);
        }
        catch(Exception ex){}
        return false;
    }
    

提交回复
热议问题