java,过滤去掉文件名非法字符

为了合理性,过滤文件名非法字符是必须的,果断地要干掉.....

有时候数据库读出来的名字无法再本地创建文件,需要去掉非法字符。

windows现在已知的文件名非法字符有 \ / : * ? " < > |

private static Pattern FilePattern = Pattern.compile("[\\\\/:*?\"<>|]");

public static String filenameFilter(String str) {

return str==null?null:FilePattern.matcher(str).replaceAll("");

}

---------------------

作者:xiejx618

来源:CSDN

原文:https://blog.csdn.net/xiejx618/article/details/17471819

版权声明:本文为博主原创文章,转载请附上博文链接!