Skip to content

Instantly share code, notes, and snippets.

@AnnaBoro
Created February 26, 2016 21:26
Show Gist options
  • Save AnnaBoro/3543c137301bf8b928e9 to your computer and use it in GitHub Desktop.
Save AnnaBoro/3543c137301bf8b928e9 to your computer and use it in GitHub Desktop.
create file + get directory tree
package lesson8.file;
import java.io.File;
public class DemoFile {
public static void main(String[] args) {
createFile();
File fileTest = new File("/Users/anna/Documents/directorytest");
getFolderTree(fileTest);
}
public static void createFile() {
File file = new File("file", "test.txt");
file.mkdirs();
System.out.println(file.getAbsolutePath());
}
public static void getFolderTree(File file) {
for (File f : file.listFiles()) {
if(f.isFile())
System.out.print("\t");
System.out.println(f.getName());
if (f.isDirectory()) {
System.out.print("\t");
getFolderTree(f);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment