找不到符号 - 符号:方法lastIndexOf(java.lang.String)location:class java.util.Scanner

时间:2021-11-07 22:09:16

My code tries to extract a filename to load a file from reading another file that contains the filename:

我的代码尝试提取文件名以从读取包含文件名的另一个文件加载文件:

public static void main(String[] args) throws IOException
{
    Scanner scan;
    String transFilename;
    String filename;

    scan = new Scanner(System.in);
    System.out.print("Enter the name of your transaction file please (include .txt extension): ");
    transFilename = scan.nextLine();
    scan = new Scanner(new FileReader(transFilename));

    filename = readLine.next(2,readLine.lastIndexOf(""));    
    Scanner input = new Scanner( new FileReader(filename));   
}

the Error generated:

生成的错误:

blah.java:72: cannot find symbol
symbol  : method lastIndexOf(java.lang.String)
location: class java.util.Scanner
            filename = readLine.next(2,readLine.lastIndexOf(""));    
                                               ^
1 error

The same error is generated when i tried to use ".length" method that should be built into java...

当我尝试使用应该内置到java中的“.length”方法时,会生成相同的错误...

2 个解决方案

#1


0  

It seems readLine is of type Scanner and you are trying to invoke lastIndexOf() but thi method doesn't belong to Scanner class

似乎readLine是Scanner类型,你试图调用lastIndexOf()但是这个方法不属于Scanner类

#2


0  

Your readLine is java.util.Scanner... I guess you're thinking that it's a java.lang.String.

你的readLine是java.util.Scanner ...我想你认为它是一个java.lang.String。

#1


0  

It seems readLine is of type Scanner and you are trying to invoke lastIndexOf() but thi method doesn't belong to Scanner class

似乎readLine是Scanner类型,你试图调用lastIndexOf()但是这个方法不属于Scanner类

#2


0  

Your readLine is java.util.Scanner... I guess you're thinking that it's a java.lang.String.

你的readLine是java.util.Scanner ...我想你认为它是一个java.lang.String。