IOException: 文件名、目录名或卷标语法不正确

问题描述:创建文件夹或者文件的时候报的异常

在这里插入图片描述

在这里插入图片描述

解决过程:

在电脑上新增一个名字为 我的我的<>??、。/>fdvd<\ 文件,会发现提示如下:

在这里插入图片描述

把违法的字符给替换掉即可

public static String replaceIllegalFileName(String fileName) {
    
    
    return fileName.replace("\\", "-")
            .replace("/", "")
            .replace(":", "")
            .replace("*", "")
            .replace("?", "")
            .replace("\"", "")
            .replace("<", "")
            .replace(">", "")
            .replace("|", "");
}

猜你喜欢

转载自blog.csdn.net/weixin_43888891/article/details/130595625
今日推荐