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


报错原因:

Connected to the target VM, address: '127.0.0.1:4771', transport: 'socket'
java.io.IOException: 文件名、目录名或卷标语法不正确。
	at java.io.WinNTFileSystem.createFileExclusively(Native Method)
	at java.io.File.createNewFile(File.java:1012)
	at com.zhiyin.generate.MyTest.main(MyTest.java:23)
Disconnected from the target VM, address: '127.0.0.1:4771', transport: 'socket'

解决方案:

public static void main(String[] args) {
    // String filename = "D:/temp/Screenshot-2020-03-19_15:52:28.jpg";  // 报错
    String filename = "D:/temp/Screenshot-2020-03-19_15-52-28.jpg";  // 正常
    File file = new File(filename);
    try {
        file.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

将文件路径中的英文冒号去掉


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM