编译器一直在为Scanner说未定义的构造函数

时间:2013-10-24 21:15:16

标签: java compiler-errors

构造函数java.util.Scanner(java.util.Scanner)未定义 我不明白为什么它一直说它未定义 和NoSuchElementException说它不能解析为一个类型而in.Close也不会工作

import java.io.*;
import java.util.Scanner;


public class MatchUp
{
public static void main(String args[]){

printHeader();
readFile(args[0]);


}
 //********************************************************************    
public static void readFile(String filename)       //Method to read file 
 {

 try
 {
File in = new File(filename);
Scanner inFile = new Scanner(inFile);
int count = 0;

while(inFile.hasNextLine()){
String line = inFile.nextLine();
String out = "";

for(int i = 0; i < line.length(); i ++){
char ch = line.charAt(i);
out = out + ch;

if(ch == '{'){
count = count + 1;
out= out + " " + count;
}
  else if (ch == '}'){
  out= out + " " + count;
  if(count > 0){
    count = count -1;
  }
   }
   }
   }
   }

  catch (FileNotFoundException exception){ 
     System.out.println("File not found."); }
  catch (NoSuchElementException exception) { 
     System.out.println("File contents invalid."); }
  catch (IOException exception) { 
     exception.printStackTrace(); 
  } 
  finally
  {
  in.close();
  }
  }

1 个答案:

答案 0 :(得分:0)

Scanner inFile = new Scanner(inFile);
        ^^^^^^               ^^^^^^

毫无意义。你可能正在寻找

Scanner inFile = new Scanner(in);
        ^^^^^^               ^^