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