`
Gavin.Chen
  • 浏览: 325692 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

ProjectFilesPrinter

阅读更多
import java.io.File;

/**  
 * @author Dao
 *   
 */
public class ProjectFilesPrinter
{
  private static int packageLevel = 0;
  private static int packageNumber = 0;
  /**  
   * @param args  
   */
  public static void main(String[] args)
  {
    String packageBasePath = "G:\\spring\\spring-framework-2.5\\src\\main\\java\\org";
    
    File file = new File(packageBasePath);
    
    showPackage(file, "");
  }
  
  private static void showPackage(File file, String basePath)
  {
    packageLevel++;
    
    String name = file.getName();
    
    if (file.isDirectory())
    {
      packageNumber++;
      
      String packagePath = basePath + name;
      
      print("+ " + packagePath);
      
      File[] subFiles = file.listFiles();
      
      for (File subFile : subFiles)
      {
        showPackage(subFile, packagePath + ".");
      }
    }
    else
    {
      String fileName = basePath + name;
      
      print("- " + fileName);
    }
    
    packageLevel--;
  }
  
  private static void print(String message)
  {
    String space = "  ";
    
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < packageLevel; i++)
    {
      sb.append(space);
    }
    
    sb.append(message);
    
    System.out.println(sb.toString());
  }
}

 效果

  + org
    + org.springframework
      + org.springframework.aop
        - org.springframework.aop.Advisor.java
        - org.springframework.aop.AfterAdvice.java
        - org.springframework.aop.AfterReturningAdvice.java
        - org.springframework.aop.AopInvocationException.java
        + org.springframework.aop.aspectj
          - org.springframework.aop.aspectj.AbstractAspectJAdvice.java
          - org.springframework.aop.aspectj.AspectInstanceFactory.java
          - org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.java
.........

.........

.........

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics