文件放到同一包下,或者使用文件的绝对路径
System.out.println(new File("").getAbsolutePath());
你的new File 的路径可能不对, 你试一下 new File("src/hamlet(1).txt")