ตัวอย่าง
package demo.directory; import java.io.File; public class DisplayDirectoryAndFile { /** * @param args */ public static void main(String[] args) { displayIt(new File("C:\\users\\nopphanan7\\Directory1")); } public static void displayIt(File node) { System.out.println(node.getAbsoluteFile()); if (node.isDirectory()) { String[] subNote = node.list(); for (String filename : subNote) { displayIt(new File(node, filename)); } } } }ผลลัพธ์ที่ได้คือ
C:\users\nopphanan7\Directory1 C:\users\nopphanan7\Directory1\FIO.jpg C:\users\nopphanan7\Directory1\photo.jpg C:\users\nopphanan7\Directory1\photo2.jpg C:\users\nopphanan7\Directory1\test1 C:\users\nopphanan7\Directory1\the_dark_knight.jpg C:\users\nopphanan7\Directory1\ubuntu-black-1440x900.jpg
0 comments:
Post a Comment