Search code examples
javapathfilesystemsjvm-languages

A clean way to copy directory contents between different file systems?


I want to copy files from one java.nio.file.FileSystem to another one. For example, from default file system to com.google.common.jimfs.Jimfs.


Solution

  • I've written some utility classes for this use case. The library is Open Source, maybe you find it useful:

    CopyFileVisitor.copy(srcPath, targetPath);  
    

    Maven:

    <dependency>
        <groupId>org.softsmithy.lib</groupId>
        <artifactId>softsmithy-lib-core</artifactId>
        <version>0.5</version>
    </dependency>
    

    Tutorial: http://www.softsmithy.org/softsmithy-lib/lib/0.5/docs/tutorial/nio-file/index.html

    Javadoc: http://www.softsmithy.org/softsmithy-lib/lib/0.5/docs/api/softsmithy-lib-core/index.html

    Source code: http://github.com/SoftSmithy/softsmithy-lib