[FileReader] 파일 읽어 들여 출력하기
1. getResourceAsStream 이용하기
<%
String path = "notice.txt";
BufferedReader br = null;
char[] buff = new char[512];
int len = -1;
try{
br = new BufferedReader(
new InputStreamReader(
application.getResourceAsStream(path)
, "UTF-8"));
while((len = br.read(buff)) != -1){
out.println(new String(buff, 0, len));
}
}catch(IOException ie){
ie.getStackTrace();
}finally{
if(br != null){
try{
br.close();
}catch(IOException ie){};
}
}
%>
2. getResource 이용하기
<%
String path1 = "notice.txt";
BufferedReader br1 = null;
char[] buff1 = new char[512];
int len1 = -1;
try{
URL url = application.getResource(path1);
br1 = new BufferedReader(
new InputStreamReader(
url.openStream()
, "UTF-8"));
while((len1 = br1.read(buff1)) != -1){
out.println(new String(buff1, 0, len1));
}
}catch(IOException ie){
ie.getStackTrace();
}finally{
if(br != null){
try{
br1.close();
}catch(IOException ie){};
}
}
%>