java IOException 및 문자열 입력 예제

*** 검색어: nabiro, java, IOException, 문자열 입력

만일 아래의 소스에서 try ~ catch 를 이용하여 IOException 예외 처리를 하지 않는다면 아래와 같은 에러를 만날 수 있습니다. 

--- 에러메세지 <시작> ---
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
Unhandled exception type IOException
--- 에러메세지 <끝> ---

//filename: inputTest.java
//

import java.io.*;
public class inputTest {
	public static void main(String[] args) {
		System.out.println("Start");
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int age=0;
		
		try {
			System.out.print("나이=");
			age = Integer.parseInt(in.readLine());
		}catch(IOException ie) {		
			System.out.println("IOException occured.");
			System.exit(1);
		}
		System.out.println("나이:" + age);	
		
		System.out.println("End");
	}
}

댓글

Designed by JB FACTORY