import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class HangulwordCount {
// 한글만 추출
private static String getHangul(String str) {
return str.replaceAll("[^\uAC00-\uD7AF\u1100-\u11FF\u3130-\u318F]", "");
}
// 디렉토리내 파일 추출
private static String[] getFileList(File targetPath) {
return targetPath.list();
}
//실행 메소드
public static void main(String[] args) {
String[] flist = getFileList(new File("C:\\test\\lang\\"));
int textTotal = 0;
for (int i = 0; i < flist.length; i++) {
File file = new File("C:\\test\\lang\\"+flist[i]);
String text = "";
String textall = "";
try {
//BufferedReader br = new BufferedReader(new FileReader(file));
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
while ((text = br.readLine()) != null) {
textall += getHangul(text);
}
br.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
textTotal += textall.length();
System.out.println(flist[i]+" : "+textall.length());
}
System.out.println("File count : " + flist.length);
System.out.println("total count : " + textTotal);
}
}