java.io.File vs java.nio.Files which is the preferred in new code?

File has a newer implementation: Path. With a builder Paths.get("..."). And Files has many nice utility functions with better implementations too (move instead of the sometimes failing File.renameTo).

A Path maintains its file system. Hence you can copy out of a zip file system ("jar:file:..... .zip") some path to another file system and vice versa.

File.toPath() may help an incremental transition.

The utilities alone in Files make a move to the newer classes profitable.


The documentation that you linked give the answer:

The java.nio.file package defines interfaces and classes for the Java virtual machine to access files, file attributes, and file systems. This API may be used to overcome many of the limitations of the java.io.File class. The toPath method may be used to obtain a Path that uses the abstract path represented by a File object to locate a file. The resulting Path may be used with the Files class to provide more efficient and extensive access to additional file operations, file attributes, and I/O exceptions to help diagnose errors when an operation on a file fails.


I would say that neither is "preferred". Instead, I would recommend that you look at the functionality your application requires and use which of java.io.File or java.nio.Files meets the requirements better.

The answer is likely to be either a draw, or java.nio.Files is better. But it is up to you or your team to decide, not some other programmer on SO.


Is this an active argument in the Java community?

There are some people who will argue about anything. But I would say that the community (in general) has more important concerns.