找不到符号 -- 符号:方法 lastIndexOf(java.lang.String) 位置:类 java.util.Scanner

发布于 2024-11-02 22:28:07 字数 880 浏览 1 评论 0原文

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

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));   
}

生成的错误:

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

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

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天暗了我发光 2024-11-09 22:28:07

看来 readLine 的类型为 Scanner 并且您正在尝试调用 lastIndexOf() 但该方法不属于 扫描仪

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

初见你 2024-11-09 22:28:07

您的 readLine 是 java.util.Scanner...我猜您认为它是 java.lang.String。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文