scanarray.java

来自「基于Java的地图数据管理软件。使用MySQL数据库管理系统。」· Java 代码 · 共 81 行

JAVA
81
字号
package net.aetherial.gis.our.allauto.create;

import java.io.File;

/**
 * <p>Title: </p>
 *
 * <p>Description: 扫描数组的文件目录</p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class ScanArray {
  private final String[] arrayFile = {
      "xiangzhen.txt", "cun.txt", "jinji.txt", "renkou.txt", "shouru.txt",
      "mianji.txt", "zirancun.txt", "dixing.txt", "tiaojian.txt", "dukou.txt",
      "beizhu.txt"};
  private String arrayPath = "";
  public ScanArray(String inputPath) {
    this.find(inputPath);
  }
  /**
   * 得到数组的路径
   */
  public String getArrayPath(){
    return this.arrayPath;
  }
  private void find(String path){
    File f = new File(path);
    if (isArrayExist(path)) {
      this.arrayPath = getEndWithSlash(path);
      return;
    }
    File[] all = f.listFiles();
    if (all == null) {
      return;
    }
    else {
      for (int i = 0; i < all.length; i++) {
        if (all[i].isDirectory()) {
          find(all[i].getAbsolutePath());
        }
//        if (this.isArrayExist(all[i].getAbsolutePath())) {
//          return;
//        }
      }
    }
  }
  /**
   * 判断directory目录下array是否齐全,
   * 如果齐全的话,return true;
   */
  private boolean isArrayExist(String directory) {
    File aFile = null;
    for (int i = 0; i < arrayFile.length; i++) {
      aFile = new File(getEndWithSlash(directory) + arrayFile[i]);
      if (!(aFile.exists())) {
        return false;
      }
    }
    return true;
  }

  /**
   * 得到后面有斜杠的字符串。
   */
  private String getEndWithSlash(String directory) {
    if ( (directory.endsWith("\\")) || (directory.endsWith("/"))) {
      return directory;
    }
    else {
      return directory + "\\";
    }
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?