内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

Java掃描文件夾下所有文件名

MIS內(nèi)容項目系統(tǒng),基于文檔資源管理管理的,需要掃描一個文件夾下面的所有文件,需求的代碼實現(xiàn)。

讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名申請、網(wǎng)絡(luò)空間、營銷軟件、網(wǎng)站建設(shè)、吉木薩爾網(wǎng)站維護、網(wǎng)站推廣。

package q.test.filescanner; 

import java.io.File; 
import java.util.ArrayList; 
import java.util.LinkedList; 

import q.test.filescanner.exception.ScanFilesException; 

/** 
 * @author 
 */ 
public class FolderFileScanner { 

  private static ArrayList<Object> scanFiles = new ArrayList<Object>(); 

  /**linkedList實現(xiàn)**/ 
  private static LinkedList<File> queueFiles = new LinkedList<File>(); 


  /** 
   * TODO:遞歸掃描指定文件夾下面的指定文件 
   * @return ArrayList<Object> 
   * @author
   * @time 2017年11月3日 
   */ 
  public static ArrayList<Object> **scanFilesWithRecursion**(String folderPath) throws ScanFilesException{ 
    ArrayList<String> dirctorys = new ArrayList<String>(); 
    File directory = new File(folderPath); 
    if(!directory.isDirectory()){ 
      throw new ScanFilesException('"' + folderPath + '"' + " input path is not a Directory , please input the right path of the Directory. ^_^...^_^"); 
    } 
    if(directory.isDirectory()){ 
      File [] filelist = directory.listFiles(); 
      for(int i = 0; i < filelist.length; i ++){ 
        /**如果當前是文件夾,進入遞歸掃描文件夾**/ 
        if(filelist[i].isDirectory()){ 
        //絕對路徑名字符串
          dirctorys.add(filelist[i].getAbsolutePath()); 
          /**遞歸掃描下面的文件夾**/ 
          **scanFilesWithRecursion**(filelist[i].getAbsolutePath()); 
        } 
        /**非文件夾**/ 
        else{ 
          scanFiles.add(filelist[i].getAbsolutePath()); 
        } 
      } 
    } 
    return scanFiles; 
  } 

  /** 
   * 
   * TODO:非遞歸方式掃描指定文件夾下面的所有文件 
   * @return ArrayList<Object> 
   * @param folderPath 需要進行文件掃描的文件夾路徑 
   * @author 
   * @time 2017年11月3日 
   */ 
  public static ArrayList<Object> scanFilesWithNoRecursion(String folderPath) throws ScanFilesException{ 
    File directory = new File(folderPath); 
    if(!directory.isDirectory()){ 
      throw new ScanFilesException('"' + folderPath + '"' + " input path is not a Directory , please input the right path of the Directory. ^_^...^_^"); 
    } 
    else{ 
      //首先將第一層目錄掃描一遍 
      File [] files = directory.listFiles(); 
      //遍歷掃出的文件數(shù)組,如果是文件夾,將其放入到linkedList中稍后處理 
      for(int i = 0; i < files.length; i ++){ 
        if(files[i].isDirectory()){ 
          queueFiles.add(files[i]); 
        }else{ 
          //暫時將文件名放入scanFiles中 
          scanFiles.add(files[i].getAbsolutePath()); 
        } 
      } 

      //如果linkedList非空遍歷linkedList 
      while(!queueFiles.isEmpty()){ 
        //移出linkedList中的第一個 
        File headDirectory = queueFiles.removeFirst(); 
        File [] currentFiles = headDirectory.listFiles(); 
        for(int j = 0; j < currentFiles.length; j ++){ 
          if(currentFiles[j].isDirectory()){ 
            //如果仍然是文件夾,將其放入linkedList中 
            queueFiles.add(currentFiles[j]); 
          }else{ 
            scanFiles.add(currentFiles[j].getAbsolutePath()); 
          } 
        } 
      } 
    } 

    return scanFiles; 
  } 
} 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

當前標題:Java掃描文件夾下所有文件名
文章源于:http://www.rwnh.cn/article26/ipggcg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、小程序開發(fā)、網(wǎng)站維護、網(wǎng)站排名、網(wǎng)站設(shè)計公司、微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
江西省| 遵义市| 涡阳县| 竹北市| 三台县| 富裕县| 长海县| 平塘县| 囊谦县| 泸西县| 辽源市| 简阳市| 兴义市| 元阳县| 厦门市| 峨眉山市| 灵台县| 太谷县| 涪陵区| 大竹县| 宣武区| 祁东县| 高要市| 伊金霍洛旗| 余干县| 田东县| 神农架林区| 峡江县| 京山县| 天长市| 阿图什市| 阿拉善盟| 龙南县| 邳州市| 化州市| 邮箱| 浮梁县| 仁布县| 格尔木市| 双流县| 漳州市|