When moving the directory tree in Java 7, use the Paths and Files functions. They not only make reading directories and files easier, but also faster than the "old" File method.
Suppose you have two directories: mainDir and otherDir , and you want to go through all the directories of mainDir to its leaves. With each entry in maiondir (file, subdirectory, symbolic link, ...) you want to compare this entry and its attributes (size, modification time ...) with the entry in the same position in otherDir . Then this will be your code:
public final void test() throws IOException, InterruptedException { final Path mainDir = Paths.get("absolute path to your main directory to read from"); final Path otherDir = Paths.get("absolute path to your other directory to compare");
What is he not :
- Find entries that exist in
otherDir but not in mainDir Path and BasicFileAttributes not Serializable , so there is no easy way to do this on two different machines.
source share