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!

Raúl
  • 1,542
  • 4
  • 24
  • 37
  • 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 Apr 20 '15 at 11:27
  • 1
    check [here](https://blogs.oracle.com/slc/entry/javanio_vs_javaio). – SilentKnight Apr 20 '15 at 11:29
  • 2
    @Kayman - sorry, but if you are right, how come http://stackoverflow.com/questions/40471/differences-between-hashmap-and-hashtable has 1500+ votes ? – Raúl Apr 20 '15 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 Apr 20 '15 at 11:43
  • I admit I didn't ask 'right' question, but I don't think its a good idea downvoting / flagging a question - just because its found on javadoc. Almost everything is on Javadoc, but we are here on SO to know/clarify things. – Raúl Apr 20 '15 at 11:51
  • 1
    as this question is first in my google search, the question here explain more on this: https://stackoverflow.com/q/10372066/3551126 and the link in its comment https://en.wikipedia.org/wiki/Non-blocking_I/O_(Java)#JDK_7_and_NIO.2 – teik Sep 18 '18 at 10:26

2 Answers2

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.

Vimal Bera
  • 10,346
  • 4
  • 25
  • 47
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.

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89