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.
Yes, but many existing APIs, including Java7's own standard APIs, still work only with
File
type.Java.io.File is not deprecated. Yes java.nio.file.Path is better, but as long as there are still plenty of programs and text books using Java.io.File, if only for legacy reasons, it should not be considered deprecated, its too important. Doing so would just be throwing a spanner in the works for no over all gain. For example the Android framework uses File for some of its basic file handling features, many other things do to.
Check this article about more info - http://www.oracle.com/technetwork/articles/javase/nio-139333.html
Basically file.Path will be the way to go from now on but as is widely known Java people tend to keep back-compatibility so I guess that's why they have left it.
Long story short:
java.io.File
will most likely never be deprecated / unsupported. That said,java.nio.file.Path
is part of the more modernjava.nio.file
lib, and does everythingjava.io.File
can, but generally in a better way, and more.For new projects, use
Path
.And if you ever need a
File
object for legacy, just call Path#toFile()Migrating from File to Path
This Oracle page highlights differences, and maps
java.io.File functionality
tojava.nio.file lib (including Path) functionality
Article by Janice J. Heiss and Sharon Zakhour, May 2009, discussing NIO.2 File System in JDK 7
This is a bit like saying: "should Napoleon invade Russia, or are these Brussels sprouts really tasty?"
As to the second part of the question, you can indeed consider it deprecated. As of January 2018, it isn't deprecated. But there's nothing to stop you considering it so. Whether that will procure you any advantage in this life or the next is impossible to say.
No, you can't consider it deprecated unless and until it is so marked in the
File
Javadoc.