try {
Scanner in = new Scanner(Paths.get("C:\Users\Administrator\IdeaProjects\untitled2\src\test\myfile.txt"),"UTF-8");
} catch (IOException ioException) {
ioException.printStackTrace();
}
ps:
1.打印当前工作路径System.out.println(System.getProperty("user.dir"));
效果图: