开发者社区> 问答> 正文

Java scanner file 报错的问题 ?报错

在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);   

Scanner inputFile = new Scanner(file); //这一句系统报错

      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)

展开
收起
爱吃鱼的程序员 2020-06-22 23:44:34 473 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    OneDrive下的文件,可能不在本地,你最好不要用这个,换一个别的路径,本地存在的文件看看

    2020-06-22 23:44:52
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载