Java 无法实例化类型扫描程序

Java 无法实例化类型扫描程序,java,java.util.scanner,Java,Java.util.scanner,我是Java新手。我想通过扫描仪读取输入。 我收到错误,因为无法“实例化类型扫描程序” import java.util.*; import java.io.File; public class Factors { //string declaration static String filename; public static void main(String args[]){ //scanner initialization, needs to be

我是Java新手。我想通过扫描仪读取输入。 我收到错误,因为无法“实例化类型扫描程序”

import java.util.*;  
import java.io.File;  

public class Factors {  

//string declaration  
static String filename;  

public static void main(String args[]){  
    //scanner initialization, needs to be done in every program that reads from user  
    Scanner input = new Scanner(System.in);  
    int caseIndex=0;  

    //prompts user for filename  
    System.out.println("Please enter the name of the file you would like to read from.");  
    filename = input.nextString();  

    //checks if filename exists  
    if(input.exists())  
        System.out.println(inp.getName() + "exists!");  
    else  
        System.out.println("File name does not exist!");  



 }  

}
我不明白我缺少什么。
请帮忙。提前感谢。

Scanner
没有方法
nextString()
exists()
方法。我想你的要求是检查文件是否存在。这样做:

    import java.util.*;  
    import java.io.File;  

    public class Factors 
    { 
        static String filename;  
     public static void main(String[] args) 
     {
            //scanner initialization, needs to be done in every program that reads from user  
            Scanner input = new Scanner(System.in);  
            int caseIndex=0;  

            //prompts user for filename  
            System.out.println("Please enter the name of the file you would like to read from.");  
            filename = input.nextLine();  
            File file=new File(filename);
            //checks if filename exists  
            if(file.exists())  
                System.out.println(file.getName() + "exists!");  
            else  
                System.out.println("File name does not exist!");  
    }

}

请添加相关代码。否则,我们只能猜测出哪里出了问题。有多个
扫描仪
类型。您确定正在使用
java.util.Scanner
?java区分大小写。确保有新的扫描仪(…)而不是新的扫描仪(…)导入java.util.Scanner;公共类StringVariables{Scanner user_input=new Scanner(System.in);}添加了代码,但未获得输出