java吧 关注:1,194,667贴子:12,613,203
  • 4回复贴,共1

初学java,文件读入的时候遇到一个错误。请热心吧友进来看看。

只看楼主收藏回复

import java.util.*;
public class InputTest {
public static void main(String args[]){
Scanner in=new Scanner(new File("c:\\test.txt"));
System.out.println("What is your name?");
String name=in.nextLine();
System.out.println("How old are you?");
int age=in.nextInt();
++age;
System.out.println("Hello, "+name+".Next year,you'll be "+age);
System.out.printf("%tc",new Date());}
}
然后提示这个错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unhandled exception type FileNotFoundException
at InputTest.main(InputTest.java:10)
请大神们看看吧~


1楼2013-03-06 16:52回复
    异常捕获try{}catch(){}


    3楼2013-03-06 17:19
    回复

      import java.io.File;
      import java.io.FileNotFoundException;
      import java.util.*;
      public class a {
      public static void main(String args[]) throws FileNotFoundException{
      Scanner in=new Scanner(new File("c:\\test.txt"));
      System.out.println("What is your name?");
      String name=in.nextLine();
      System.out.println("How old are you?");
      int age=in.nextInt();
      ++age;
      System.out.println("Hello, "+name+".Next year,you'll be "+age);
      System.out.printf("%tc",new Date());}
      }
      这样子试试看


      4楼2013-03-06 17:34
      回复
        可能是找不到文件,你这个文件有没有建立了


        来自Android客户端5楼2013-03-06 17:38
        回复