All file names in the Java scan folder.
MIS content project system, based on document Resource Management, needs to scan all the files under a folder, the required code implementation.
Package q. test. filepath; import java. io. file; import java. util. arrayList; import java. util. using list; import q. test. filepath. exception. scanFilesException;/*** @ author */public class folderfile={ private static ArrayList <Object> scanFiles = new ArrayList <Object> (); /** implement the secure list **/private static secure list <File> queueFiles = new secure list <File> ();/*** TODO: recursively scans the specified files in the specified folder *@ Return ArrayList <Object> * @ author * @ time November 3, 2017 */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. ^_^... cmd_^ ");} if (directory. isDirectory () {File [] filelist = directory. listFiles (); for (int I = 0; I <filelist. length; I ++) {/** if it is a folder, go to the recursive scan folder **/if (filelist [I]. isDirectory () {// absolute path name string dirctorys. add (filelist [I]. getAbsolutePath ()); /** Recursively scan the following folder **/** scanFilesWithRecursion ** (filelist [I]. getAbsolutePath ();}/** non-Folder **/else {scanFiles. add (filelist [I]. getAbsolutePath () ;}} return scanFiles;}/***** TODO: scan all files under a specified folder in non-recursive mode * @ return ArrayList <Object> * @ param folderPath: folder path to be scanned * @ author * @ time November 3, 2017 */public static ArrayList <Object> scanFilesWithNoRecursion (String folderPath) throws ScanFilesException {F Ile 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. ^_^... pai_^ ");} else {// first scan the first directory again File [] files = directory. listFiles (); // traverse the scanned file array. If it is a folder, put it into the sorted list and process it later for (int I = 0; I <files. length; I ++) {if (files [I]. isDirectory () {queueFiles. add (files [I]);} else {// temporarily put the file name in scanFiles for scan Files. add (files [I]. getAbsolutePath () ;}// if the program list is not empty, traverse the program list while (! QueueFiles. isEmpty () {// remove the first File headDirectory = queueFiles from the queue list. removeFirst (); File [] currentFiles = headDirectory. listFiles (); for (int j = 0; j <currentFiles. length; j ++) {if (currentFiles [j]. isDirectory () {// if it is still a folder, put it into the queue list queueFiles. add (currentFiles [j]);} else {scanFiles. add (currentFiles [j]. getAbsolutePath () ;}}} return scanFiles ;}}
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.