
Throwable 클래스의 getFile() 메서드는 Throwable 객체가 발생한 파일 경로를 반환합니다.
예를 들어, IOException을 발생시키는 코드가 다음과 같을 때 getFile() 메서드는 해당 코드의 파일 경로를 반환합니다.
#hostingforum.kr
java
public class Main {
public static void main(String[] args) {
try {
// 예외가 발생하는 코드
File file = new File("example.txt");
if (!file.exists()) {
throw new IOException("파일이 존재하지 않습니다.");
}
} catch (IOException e) {
System.out.println(e.getMessage());
System.out.println(e.getFile()); // getFile() 메서드가 반환하는 파일 경로
}
}
}
getFile() 메서드는 Throwable 객체의 원인에 대한 파일 경로를 반환하는 것이 아닙니다.
2025-08-03 04:16