检索中文工具(SearchZhUtil)

来源:互联网 发布:淘宝网络电话 编辑:程序博客网 时间:2024/05/16 19:11

 

static Long COUNT = 0L;

 static String OUT_FILE_NAME = "D:/zhang_zchao/workspace5.5/test/src/memo.2.txt";

 static String CODE_PATH = "D:/zhang_zchao/workspace5.5/test/src";

 /**
  * 检索一个目录或文件的中文
  */
 public static void main(String[] args) {
  // System.out.println(args[0]);

  searchFile(CODE_PATH);
  System.out.println("over");
 }

 public static void countTotal(String directory) {
  File f = new File(directory);
  if (f.isFile()) {
   countZH(f);
  } else {
   File[] fs = f.listFiles();
   for (File file : fs) {
    countTotal(file.getPath());
   }
  }
 }

 public static void searchFile(String directory) {

  File f = new File(directory);
  if (f.isFile()) {
   comileFile(f);
  } else {
   File[] fs = f.listFiles();
   for (File file : fs) {
    searchFile(file.getPath());
   }
  }

 }

 private static long countZH(File f) {

  String filename = f.getPath();

  if (!filename.contains("i18n")) {
   return 0L;
  }
  System.out.println(filename);
  long count = 0L;

  List<String> users = readFile(f.getPath());

  for (String content : users) {
   // System.out.println(content);
   if (content == null || "".equals(content.trim())) {
    continue;
   }
   content = content.trim();
   for (int i = 0; i < content.length(); i++) {
    String ss = content.substring(i, i + 1);
    if (ss.getBytes().length == 2) {
     count++;
    }
   }
  }
  System.out.println(count);
  COUNT += count;
  return count;

 }

 

原创粉丝点击