| 디렉토리를 인자로 주면 해당 폴더 아래의 모든 디렉토리와 파일을 뒤지는 visitAllDirsAndFiles 메소드와
디렉토리만 뒤지는 visitAllDirs 메소드를 소개 합니다. visitAllDirsAndFiles 메소드는 기술한 폴더의 모든 디렉토리와 파일을 탐색하는데 process 메소드는 적당히 필요에 따라 만들어 쓰시면 되구여, 예를들면 디렉톨리 이름을 출력 한다든지... 예제를 참고 하세요~ // Process all files and directories under dir public static void visitAllDirsAndFiles(File dir) { // You can do whatever you want with this directory // E.g. printing its name to the console process(dir); if (dir.isDirectory()) { String[] children = dir.list(); for (int i=0; i<children.length; i++) { visitAllDirsAndFiles(new File(dir, children[i])); } } } // Process only directories under dir public static void visitAllDirs(File dir) { if (dir.isDirectory()) { // You can do whatever you want with this directory // E.g. printing its name to the console process(dir); String[] children = dir.list(); for (int i=0; i<children.length; i++) { visitAllDirs(new File(dir, children[i])); } } }
오라클자바커뮤니티 실전 강좌 - 개인80% 환급
SQL초보에서실전전문가까지
|
2013년 9월 5일 목요일
자바 디렉토리 하위 탐색 하기 자바 폴더, JAVA DIRECTORY, 오라클자바커뮤니티 자바강좌
자바 디렉토리 하위 탐색 하기 자바 폴더, JAVA DIRECTORY, 오라클자바커뮤니티 자바강좌
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기