Java 8: Kopieren Verzeichnis rekursiv?

Sehe ich, dass Java 8 hat deutlich bereinigt Lesen den Inhalt einer Datei in einen String:

String contents = new String(Files.readAllBytes(Paths.get(new URI(someUrl))));

Frage ich mich, ob es etwas ähnliches (sauberer/weniger-code/präziser), für das kopieren von Verzeichnissen rekursiv. In Java 7 land, es ist immer noch so etwas wie:

public void copyFolder(File src, File dest) throws IOException{
    if(src.isDirectory()){
        if(!dest.exists()){
            dest.mkdir();
        }

        String files[] = src.list();

        for (String file : files) {
            File srcFile = new File(src, file);
            File destFile = new File(dest, file);

            copyFolder(srcFile,destFile);
        }

    } else {
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dest); 

        byte[] buffer = new byte[1024];

        int length;
        while ((length = in.read(buffer)) > 0){
            out.write(buffer, 0, length);
        }

        in.close();
        out.close();
    }
}

Aller Verbesserungen, die hier in Java 8?

InformationsquelleAutor smeeb | 2015-03-16
Schreibe einen Kommentar