報錯原因:

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();
}
}
將文件路徑中的英文冒號去掉
