我的代码尝试提取文件名以加载文件,从而读取包含文件名的另一个文件:
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”方法时会产生同样的错误......
答案 0 :(得分:0)
似乎readLine
的类型为Scanner
,您尝试调用lastIndexOf()
但该方法不属于Scanner
类
答案 1 :(得分:0)
你的readLine
是java.util.Scanner ...我想你认为它是java.lang.String。