Java 7:路径与文件 [英] Java 7: Path vs File
问题描述
java.io.File
对象更多,或者我们可以认为它已弃用? 我相信 java.nio.file.Path
可以做所有事情 java.io.File
可以做更多。 / b>
长话短说:
java.io.File
最有可能不会被弃用/不被支持。也就是说, java.nio.file.Path
是更现代的 java.nio.file
lib的一部分,做一切 java.io.File
都可以,但一般情况下会更好,然后一些。对于新项目,请使用 Path
。
如果你需要一个 File
对象,只需调用 Path#toFile()
从文件迁移到路径
这个Oracle页面突出显示了不同之处,映射 java.io.File函数
到 java.nio.file lib(包括Path)功能
文章由Janice J. Heiss和Sharon Zakhour,2009年5月,讨论JDK 7中的NIO.2文件系统
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.
Long story short:
java.io.File
will most likely never be deprecated / unsupported. That said, java.nio.file.Path
is part of the more modern java.nio.file
lib, and does everything java.io.File
can, but generally in a better way, and then some.
For new projects, use Path
.
And if you ever need a File
object for legacy, just call Path#toFile()
Migrating from File to Path
Article by Janice J. Heiss and Sharon Zakhour, May 2009, discussing NIO.2 File System in JDK 7
这篇关于Java 7:路径与文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!