public static void getFilesTpye(String BasePath) {
String s, str = new String();
try {
BufferedReader in = new BufferedReader(new FileReader(BasePath));
while ((s = in.readLine()) != null) {
str += s + "\n";
}
in.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int zimunum = regexMethods("([a-zA-Z]{1})", str);
int shuzinum = regexMethods("(\\d{1})", str);
int hanzinum = regexMethods("([\u4e00-\u9fa5]{1})", str);
int kongnum = regexMethods("([\u0020]{1})", str);
System.err.println("字母: " + zimunum);
System.err.println("数字: " + shuzinum);
System.err.println("汉字: " + hanzinum);
System.err.println("空格: " + kongnum);
}
public static int regexMethods(String regex, String source) {
Pattern pattern = Pattern.compile(regex);
Matcher match = pattern.matcher(source);
int numb = 0;
while (match.find()) {
numb++;
}
return numb;
}