<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ 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=UTF-8"> <title>텍스트 파일 가져와서 화면에 출력하기</title> </head> <body> <% FileReader fr = null; char[] buf = new char[512]; int len = -1; try{ //현재 위치 : '/' '.' //.../AAA.jpg ./AA.jpg String path = application.getRealPath("/"); out.print("실제 패스="+path); fr=new FileReader(path+"/tts.txt"); while( (len = fr.read(buf)) != -1 ){ //화면에 출력하기 out.print(new String(buf,0,len)); } }catch(Exception e){ out.print("예외발생"+e.getMessage()); }finally{ if(fr != null){ fr.close(); } } %> </body> </html>
'JSP > 2012.04강의(MySQL)' 카테고리의 다른 글
2일차 pageContext,session,application,request (0) | 2012.05.22 |
---|---|
2일차 파일 읽어오기 (0) | 2012.05.22 |
2일차 기본객체 out , pageContext, application (0) | 2012.05.22 |
2일차 Buffer 관리하기&경로 (0) | 2012.05.22 |
2일차 Buffer 관리하기 (0) | 2012.05.22 |