import
java.io.BufferedReader;
import
java.io.File;
import
java.io.FileInputStream;
import
java.io.FileNotFoundException;
import
java.io.IOException;
import
java.io.InputStreamReader;
public
class
FileContentReadTest {
public
static
void
main(String[] args) {
BufferedReader br =
null
;
InputStreamReader isr =
null
;
FileInputStream fis =
null
;
File file =
new
File(
"temp/target.txt"
);
String temp =
""
;
String content =
""
;
try
{
fis =
new
FileInputStream(file);
isr =
new
InputStreamReader(fis,
"UTF-8"
);
br =
new
BufferedReader(isr);
while
( (temp = br.readLine()) !=
null
) {
content += temp +
"\n"
;
}
System.out.println(
"================== 파일 내용 출력 =================="
);
System.out.println(content);
}
catch
(FileNotFoundException e) {
e.printStackTrace();
}
catch
(Exception e) {
e.printStackTrace();
}
finally
{
try
{
fis.close();
}
catch
(IOException e) {
e.printStackTrace();
}
try
{
isr.close();
}
catch
(IOException e) {
e.printStackTrace();
}
try
{
br.close();
}
catch
(IOException e) {
e.printStackTrace();
}
}
}
}