package com.javawide.files;
import java.io.*;
public class UTF8Reader {
public static void main(String[] args) {
UTF8Reader reader = new UTF8Reader();
try {
String utf8String = reader.readFully(“C:/utf8test.txt”);
System.out.println(utf8String);
System.out.println(new String(utf8String.getBytes(), “EUC-KR”));
} catch (Exception e) {
e.printStackTrace();
}
}
public String readFully(String fileName) throws Exception {
File f = new File(fileName);
if(!f.exists()) return “No File”;
FileInputStream fis = new FileInputStream(f);
InputStreamReader in = new InputStreamReader(fis, “UTF-8”);
StringBuffer buffer = new StringBuffer();
int readed = 0;
char[] buf = new char[4096];
while(-1 != (readed = in.read(buf)))
buffer.append(buf, 0, readed);
return buffer.toString();
}
}