본문 바로가기

컴퓨터/jsp

예외처리

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
 <%@page import="java.io.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
        <title>Insert title here</title>
    </head>
    <body>
        <%
             BufferedReader reader = null;
             try {
                 String filePath = application.getRealPath("/WEB-INF/input.txt");
                 reader = new BufferedReader(new FileReader(filePath));
                 while(true){
                 String str = reader.readLine();
                 if(str==null)
                     break;
                 out.println(str + "<BR>");
             }
         }
         catch(FileNotFoundException fnfe){
             out.println("파일이 존재하지 않습니다.");
         }
         catch(IOException ioe){
             out.println("파일을 읽을 수 없습니다.");
         }
         finally{
             try{
                 reader.close();
             }
             catch (Exception e){
             }
         }
        %>
    </body>
</html> 

'컴퓨터 > jsp' 카테고리의 다른 글

예제  (0) 2013.07.06
버퍼  (0) 2013.07.06
Encoding  (0) 2013.07.06
개인정보 저장  (0) 2013.07.06
servlet  (0) 2013.07.06