报错原因:
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();
}
}
将文件路径中的英文冒号去掉