我的代碼嘗試提取一個文件名來讀取包含文件名的另一個文件加載一個文件:找不到符號 - 符號:方法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「長度」方法產生同樣的錯誤......
對不起,我忘記包含已初始化的readLine掃描儀。掃描儀readLine; readLine = new Scanner(scan.nextLine()); – john 2011-04-25 10:09:38