import java.io.File;
import java.io.FileReader;
import java.util.Scanner;
public class lab4 {
public static void main(String[] args){
/*
* Input is the name of the file and location typed by the user
* file is used as a new scanner of the file to later go into the FileReader
*/
String input;
Scanner file;
System.out.println("Please type the name of the file you wish to read into the program");
// scanner to acquire input
Scanner scanner = new Scanner(System.in);
input = scanner.nextLine();
System.out.println("the file input was " + input);
// tries to attach the specified file "input" to a new scanner "file" to later read into FileReader
try{
file = new Scanner(new File(input));
}
catch(Exception e){
System.out.println("The requested file could not be found");
}
FileReader(File file){
while(file.hasNext()){
String s = file.next();
}
}
}
}
,我已經看過了例子,什麼IM做的應該是正確的,找不出問題用的FileReader
java: ')' expected
java: illegal start of expression
java: ';' expected
java: class, interface, or enum expected
錯誤指向FileReader的位置,所以顯然我使用它錯了,我不需要;我看到的例子是公共無效FileReader(文件「文件名」)的製作方法 我被告知把我的代碼在公共靜態void main(String [] args)
我看了YouTube並擡起頭API和沒有骰子。
那你認爲'FileReader'塊是幹什麼的?它看起來像一個方法內部的方法(你不能這麼做),所以根據你的期望,你可以使它成爲一個方法或者只是創建一個FileReader實例。 – John3136