在mian 方法里面
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the filename to read from: ");
String filename = keyboard.nextLine();
System.out.print(filename);
File file = new File(filename);
StringTokenizer token;
while (inputFile.hasNext()){
String line = inputFile.nextLine();
token = new StringTokenizer(line, "");
String firstName = token.nextToken();
String lastName = token.nextToken();
String IDString = token.nextToken();
系统报错为:
Enter the filename to read from: C:\Users\15220\OneDrive\student_record.txt
C:\Users\15220\OneDrive\student_record.txtException in thread "main" java.io.FileNotFoundException: C:\Users\15220\OneDrive\student_record.txt (???????????)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(Unknown Source)
at java.base/java.io.FileInputStream.(Unknown Source)
at java.base/java.util.Scanner.(Unknown Source)
at Exercise3.Exercise3.main(Exercise3.java:15)
OneDrive下的文件,可能不在本地,你最好不要用这个,换一个别的路径,本地存在的文件看看
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。