最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實(shí)現(xiàn)遞歸文件列表的方法

 更新時間:2015年07月21日 17:06:26   作者:華宰  
這篇文章主要介紹了java實(shí)現(xiàn)遞歸文件列表的方法,實(shí)例分析了java采用遞歸算法遍歷文件的技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實(shí)例講述了java實(shí)現(xiàn)遞歸文件列表的方法。分享給大家供大家參考。具體如下:

FileListing.java如下:

import java.util.*;
import java.io.*;
/**
* Recursive file listing under a specified directory.
* 
* @author javapractices.com
* @author Alex Wong
* @author anonymous user
*/
public final class FileListing {
 /**
 * Demonstrate use.
 * 
 * @param aArgs - <tt>aArgs[0]</tt> is the full name of an existing 
 * directory that can be read.
 */
 public static void main(String... aArgs) throws FileNotFoundException {
  File startingDirectory= new File(aArgs[0]);
  List<File> files = FileListing.getFileListing(startingDirectory);
  //print out all file names, in the the order of File.compareTo()
  for(File file : files ){
   System.out.println(file);
  }
 }
 /**
 * Recursively walk a directory tree and return a List of all
 * Files found; the List is sorted using File.compareTo().
 *
 * @param aStartingDir is a valid directory, which can be read.
 */
 static public List<File> getFileListing(
  File aStartingDir
 ) throws FileNotFoundException {
  validateDirectory(aStartingDir);
  List<File> result = getFileListingNoSort(aStartingDir);
  Collections.sort(result);
  return result;
 }
 // PRIVATE //
 static private List<File> getFileListingNoSort(
  File aStartingDir
 ) throws FileNotFoundException {
  List<File> result = new ArrayList<File>();
  File[] filesAndDirs = aStartingDir.listFiles();
  List<File> filesDirs = Arrays.asList(filesAndDirs);
  for(File file : filesDirs) {
   result.add(file); //always add, even if directory
   if ( ! file.isFile() ) {
    //must be a directory
    //recursive call!
    List<File> deeperList = getFileListingNoSort(file);
    result.addAll(deeperList);
   }
  }
  return result;
 }
 /**
 * Directory is valid if it exists, does not represent a file, and can be read.
 */
 static private void validateDirectory (
  File aDirectory
 ) throws FileNotFoundException {
  if (aDirectory == null) {
   throw new IllegalArgumentException("Directory should not be null.");
  }
  if (!aDirectory.exists()) {
   throw new FileNotFoundException("Directory does not exist: " + aDirectory);
  }
  if (!aDirectory.isDirectory()) {
   throw new IllegalArgumentException("Is not a directory: " + aDirectory);
  }
  if (!aDirectory.canRead()) {
   throw new IllegalArgumentException("Directory cannot be read: " + aDirectory);
  }
 }
}

希望本文所述對大家的java程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • 用java實(shí)現(xiàn)的獲取優(yōu)酷等視頻縮略圖的實(shí)現(xiàn)代碼

    用java實(shí)現(xiàn)的獲取優(yōu)酷等視頻縮略圖的實(shí)現(xiàn)代碼

    想獲取優(yōu)酷等視頻縮略圖,在網(wǎng)上沒有找到滿意的資料,參考了huangdijia的PHP版工具一些思路,寫了下面的JAVA版代碼。。其實(shí)也可以做成JS版的
    2013-05-05
  • java多線程編程實(shí)現(xiàn)下雪效果

    java多線程編程實(shí)現(xiàn)下雪效果

    這篇文章主要介紹了java多線程編程實(shí)現(xiàn)下雪效果的相關(guān)資料,需要的朋友可以參考下
    2015-11-11
  • 新手初學(xué)Java基礎(chǔ)

    新手初學(xué)Java基礎(chǔ)

    這篇文章主要介紹了java基礎(chǔ)之方法詳解,文中有非常詳細(xì)的代碼示例,對正在學(xué)習(xí)java基礎(chǔ)的小伙伴們有非常好的幫助,需要的朋友可以參考下
    2021-07-07
  • SpringMVC實(shí)現(xiàn)數(shù)據(jù)綁定及表單標(biāo)簽

    SpringMVC實(shí)現(xiàn)數(shù)據(jù)綁定及表單標(biāo)簽

    這篇文章主要為大家詳細(xì)介紹了SpringMVC實(shí)現(xiàn)數(shù)據(jù)綁定及表單標(biāo)簽的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • PageHelper在springboot中的使用方式

    PageHelper在springboot中的使用方式

    這篇文章主要介紹了PageHelper在springboot中的使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • 一篇文章帶你入門Java字面量和常量

    一篇文章帶你入門Java字面量和常量

    這篇文章主要介紹了探究Java的常量,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-08-08
  • SpringMvc配置靜態(tài)資源訪問路徑的實(shí)現(xiàn)

    SpringMvc配置靜態(tài)資源訪問路徑的實(shí)現(xiàn)

    本文主要介紹了SpringMvc配置靜態(tài)資源訪問路徑的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • 深入講解基于JDK的動態(tài)代理機(jī)制

    深入講解基于JDK的動態(tài)代理機(jī)制

    眾所周知相比于靜態(tài)代理,動態(tài)代理避免了開發(fā)人員編寫各個繁鎖的靜態(tài)代理類,下面這篇文章主要給大家介紹了關(guān)于基于JDK的動態(tài)代理機(jī)制的相關(guān)資料,文中通過圖文以及示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2018-07-07
  • springboot配置templates直接訪問的實(shí)現(xiàn)

    springboot配置templates直接訪問的實(shí)現(xiàn)

    這篇文章主要介紹了springboot配置templates直接訪問的實(shí)現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • java判斷兩個時間是不是同一天的方法

    java判斷兩個時間是不是同一天的方法

    這篇文章主要介紹了java判斷兩個時間是不是同一天的方法,需要的朋友可以參考下
    2014-02-02

最新評論

武安市| 建德市| 兰溪市| 伊金霍洛旗| 屏边| 南京市| 教育| 滁州市| 阿克苏市| 大余县| 资源县| 深水埗区| 娱乐| 连山| 永平县| 巴青县| 阳新县| 山阴县| 南川市| 广州市| 正定县| 米脂县| 利津县| 顺平县| 贡嘎县| 桦甸市| 鸡泽县| 正阳县| 堆龙德庆县| 紫金县| 内丘县| 淄博市| 北辰区| 永康市| 陆丰市| 荃湾区| 乌拉特前旗| 山东| 临猗县| 武强县| 建瓯市|