For new applications written in Java 7, is there any reason to use a java.io.File
object any more or can we consider it deprecated?
I believe a java.nio.file.Path
can do everything a java.io.File
can do and more.
For new applications written in Java 7, is there any reason to use a java.io.File
object any more or can we consider it deprecated?
I believe a java.nio.file.Path
can do everything a java.io.File
can do and more.
I will complete the very good answer of
@mmcrae
.JDK classes are very rarely deprecated.
You can see on the the JDK 8 API deprecates list all classes deprecated since the first JDK.
It contains only a little part of classes that the Oracle documentation and the Java community discourage to use.
java.util.Date
,java.util.Vector
,java.util.Hashtable
... that are classes with so many defects are not deprecated.But why ?
Because conceptually something of
deprecated
means still there but discourage to use as it will very certainly be removed.Thousands of programs rely on these bad designed classes.
For such classes, Java API developers will not give such a signal.
Answer of
@EJP
is so really right :So, I think that your question would make more sense in its terms :
"As we have the choice, should we use
java.io.File
orjava.nio.file.Path
for new developments and if the answer isjava.nio.file.Path
, could you easily take advantage ofjava.io.File
for legacy projects usingjava.io.File
?"You have the answer.
This oracle tutorial about legacy IO confirms your thinking.
With so many drawbacks for
java.io.File
, we need really no reason to use this class for new developments.And even for legacy code using
java.io.File
, Oracle gives hints to usePath
.