5

What are the advantages or key features of Files over File ? When to prefer one & why ?

Edit: This is just another 'difference between' question in our world - so be sure that you REALLY want to downvote it!

6
  • 1
    Files is utility class holding static methods for managing file system, File is class which instances represent single path (with few additional methods allowing manipulating this path).
    – Pshemo
    Commented Apr 20, 2015 at 11:27
  • 1
    check here. Commented Apr 20, 2015 at 11:29
  • 2
    @Kayman - sorry, but if you are right, how come stackoverflow.com/questions/40471/… has 1500+ votes ?
    – Raúl
    Commented Apr 20, 2015 at 11:36
  • 1
    @Raúl Hashtable and HashMap are similar in their concept but different in their implementation so asking for a comparison is interesting. File and Files are related but not comparable, so your question does not make really sense... It's as if you had asked "Which is better: java.lang.Math or java.math.BigDecimal?"...
    – assylias
    Commented Apr 20, 2015 at 11:43
  • 1
    as this question is first in my google search, the question here explain more on this: stackoverflow.com/q/10372066/3551126 and the link in its comment en.wikipedia.org/wiki/Non-blocking_I/O_(Java)#JDK_7_and_NIO.2
    – teik
    Commented Sep 18, 2018 at 10:26

2 Answers 2

5

As per Java Docs, java.nio.file.Files class consists exclusively of static methods that operate on files, directories, or other types of files. In most cases, the methods defined here will delegate to the associated file system provider to perform the file operations.

Whereas java.io.File is an abstract representation of file and directory pathnames.

4

Files:

This class consists exclusively of static methods that operate on files, directories, or other types of files.

But file is an abstract representation of file and directory pathnames

Means Files class is an utility class to perform operations on file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.