开发者

cannot find symbol -- symbol : method lastIndexOf(java.lang.String) location: class java.util.Scanner

开发者 https://www.devze.com 2023-02-28 18:28 出处:网络
My code tries to extract a filename to load a file from reading another file that contains the filename:

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.ne开发者_JAVA百科xt(2,readLine.lastIndexOf(""));    
                                               ^
1 error

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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号