-3
    File inputTXT = new File (fileName);

    try{
    Scanner in = new Scanner(inputTXT);
    }catch(FileNotFoundException e){
        System.out.println("");
    }
        while(in.hasNext()){
            String line = in.nextLine();

It says in can't be resolved.How am I going to fix this problem?

I've tried ignored try catch block, but this file scanner has to be in the try catch block

4

1 回答 1

0

In your code you have issue about variable scope.You defined in variable in try catch block and then you used it in while loop.It should be like below:

    File inputTXT = new File (fileName);
    Scanner in=null;
    try{
     in = new Scanner(inputTXT);
    }catch(FileNotFoundException e){
        System.out.println("");
    }
        while(in.hasNext()){
            String line = in.nextLine();
于 2013-09-27T21:35:15.083 回答