Created
February 26, 2016 21:26
-
-
Save AnnaBoro/3543c137301bf8b928e9 to your computer and use it in GitHub Desktop.
create file + get directory tree
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 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