找不到符号 -- 符号:方法 lastIndexOf(java.lang.String) 位置:类 java.util.Scanner
我的代码尝试提取文件名以通过读取包含该文件名的另一个文件来加载文件:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来
readLine
的类型为Scanner
并且您正在尝试调用lastIndexOf()
但该方法不属于扫描仪
类It seems
readLine
is of typeScanner
and you are trying to invokelastIndexOf()
but thi method doesn't belong toScanner
class您的 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.