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();
}
}
}
}
로 문제를 파악하지 못할, 나는 예를 보면서 무엇을 메신저를 잘해야하고,이 난을 FileReader에 오류를 명중 각각의 새로운 추가 후 컴파일 곳에있어 프로그래밍에 몇 가지 긴 문제 이후의 FileReader
java: ')' expected
java: illegal start of expression
java: ';' expected
java: class, interface, or enum expected
오류가 FileReader 위치를 가리키고 있으므로 분명히 잘못 사용하고 있습니다. 필요하지 않습니다. 내가 본 예제는 public void FileReader (File "fileName")와 같은 메서드를 만드는 것입니다. public static void main (String [] args)에 내 코드의 전체를 넣으라고했습니다.
나는 youtube를 봤고 API 및 주사위 없음. 더 나은 코딩 연습 지역 변수 input
와 main() 메소드의 file
외부를 정의하는 아마
:
에 관계없이, 다음은 샘플입니까? 메서드 내에서 메서드처럼 보이기 때문에 (사용자가 할 수는 없습니다.) 원하는대로 메서드를 만들거나 FileReader 인스턴스를 만들 수 있습니다. – John3136