[JavaSE] IO stream (recursive FIle list of FIle objects), javaseio
Get the File object, new, and construct the parameter: String directory name
Call the list () method of the File object to obtain the name of the String [] array File.
Loop array, listing all files including hidden files
Recursively list all data
Define a static method showDir () and pass it into the parameter: FIle object
Call the listFiles () method of the File object to obtain the array of File [].
Loop File [] array, each element is a File object
In the loop, call the isDirectory () method of the File object to determine whether it is a directory. If it is a directory, call the showDir () method again. Parameter: File object
If the File object is not printed
Import java. io. file; public class FileDemo {/*** @ param args */public static void main (String [] args) {File file = new File ("E: /adt-bundle-windows/workspace/IpTest "); showDir (file );} /*** recursively display the file ** @ param File */public static void showDir (file File) {System. out. println ("Directory:" + file); File [] files = file. listFiles (); for (File dir: files) {// conditions if (dir. isDirectory () {showDir (dir);} else {System. out. println ("file:" + dir );}}}}
PHP version:
<? Phpclass FileDemo {public static function main () {FileDemo: showDir ("E:/adt-bundle-windows/workspace/IpTest ");} /*** recursively display the file * @ param file */public static function showDir ($ file) {echo "Directory :". $ file. "<br/>"; $ dirObj = dir ($ file); while ($ files = $ dirObj-> read ()) {// conditional if (is_dir ($ file. "/". $ files) & $ files! = "." & $ Files! = ".. ") {FileDemo: showDir ($ file. "/". $ files) ;}else {echo "& nbsp; file :". $ files. "<br/>" ;}}} FileDemo: main ();