Exemple #1
0
  private static void index_h(String prefix, File file, IndexWriter indexWriter)
      throws IOException {
    Document doc = null;

    if (file.isDirectory()) {
      File files[] = file.listFiles();
      for (File file1 : files) {
        index_h(prefix + FILE_SEPARATOR + file.getName(), file1, indexWriter);
      }
    } else {
      String content = FileUtils.readFileToString(file, "utf-8");

      System.out.println("==============================================================");
      System.out.println("index_h " + content);
      System.out.println("==============================================================");

      String filename = prefix + FILE_SEPARATOR + file.getName();
      String path = file.getAbsolutePath();

      doc = new Document();
      doc.add(new Field("content", content, Field.Store.YES, Field.Index.ANALYZED));
      doc.add(new Field("relative_path", filename, Field.Store.YES, Field.Index.NOT_ANALYZED));
      indexWriter.addDocument(doc);
    }
  }
 private void myDelete(String path) throws Exception {
   File f = new File(path);
   if (!f.exists()) {
     return;
   }
   if (f.isDirectory()) {
     if (f.listFiles().length == 0) {
       f.delete();
     } else {
       File delFile[] = f.listFiles();
       int i = delFile.length;
       for (int j = 0; j < i; j++) {
         if (delFile[j].isDirectory()) {
           myDelete(delFile[j].getAbsolutePath());
         } else {
           delFile[j].delete();
         }
       }
       f.delete();
     }
   } else {
     f.delete();
   }
 }
Exemple #3
0
  private boolean notEmpty(File indexPath) {

    if (indexPath.isDirectory() == false) {
      System.out.println(indexPath.toString() + " is not directory!\n");
      return false;
    }

    File[] indexs = indexPath.listFiles();

    if (indexs == null) {

      return false;
    }

    return true;
  }