이 코드를 잘못 이해합니다. 나는 Java 문서에 따라 모든 것을 설정했지만 분명히 뭔가를 이해하지 못하고있다.포매터 예외 처리
import java.io.FileNotFoundException;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
public class CreateTextFile {
private Formatter output; //object used to output text to file
public void openFile() throws FileNotFoundException {
try {
output = new Formatter("sets.txt") { //First Error
@Override
public String format(LogRecord record) {
throw new UnsupportedOperationException("Not supported yet.");
}
}; //open the file
} catch (SecurityException securityException) {
System.err.println("You do not have access to this file.");
System.exit(1); //terminate the program
} catch (FileNotFoundException fileNotFoundException) { //second error
}
}
}
첫 번째 오류 : 첫째, 여기에 코드입니다
constructor Formatter in class Formatter cannot be applied to given types; required: no arguments found: String reason: actual and formal argument lists differ in length
나는 오류 메시지를 이해하지만, 나는 동의하지 않는다. 하나의 문자열을 사용 포맷터의 생성자가 확실히있다
두 번째 오류 (아래 참조)
constructor Formatter in class Formatter cannot be applied to given types; required: no arguments found: String reason: actual and formal argument lists differ in length
나는 아래의 자바 문서에 설명 된대로 메소드 선언에서 FileNotFoundException이 던지는거야.
이
Formatter(String fileName) throws FileNotFoundException Constructs a new formatter with the specified file name.
The charset used is the default charset for this instance of the Java virtual machine.
The locale used is the default locale for this instance of the Java virtual machine.
fileName The name of the file to use as the destination of this formatter. If the file exists then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
Throws SecurityException: If a security manager is present and checkWrite(fileName) denies write access to the file
Throws FileNotFoundException: If the given file name does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
이러한 오류를 제거하는 방법을 확실하지
[http://doc.java.sun.com/DocWeb/api/java.util.Formatter][1]에서 직선이다. 누구든지 도와 줄 수 있습니까? 감사! 코드에서
Ack! 어리석은 실수에 대한 나의 역량은 경계를 모른다. 감사! – Alex