Created
January 31, 2015 21:40
-
-
Save kineticz/98ff3bee21a8ba39bcf7 to your computer and use it in GitHub Desktop.
Correct version of directory walker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package je3.io; | |
| import java.io.File; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| /** | |
| * Created by IDEA on 31/01/15. | |
| */ | |
| public class WalkDir { | |
| private List<File> recursiveList = new ArrayList<File>(); | |
| public void walkDir(String pathname) { | |
| File d = new File(pathname); | |
| recursiveList.add(d); | |
| if(d.isDirectory()) { | |
| for(String f : d.list()) { | |
| walkDir(f); | |
| } | |
| } | |
| } | |
| public List<File> getRecursiveList() { | |
| return recursiveList; | |
| } | |
| public static void main(String[] args) { | |
| WalkDir dirWalker = new WalkDir(); | |
| dirWalker.walkDir("/tmp"); | |
| dirWalker.getRecursiveList().forEach(System.out::println); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment