Java: Path vs File

后端 未结 7 1044
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 10:49

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 c

相关标签:
7条回答
  • 2020-11-27 11:43

    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 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 to java.nio.file lib (including Path) functionality

    Article by Janice J. Heiss and Sharon Zakhour, May 2009, discussing NIO.2 File System in JDK 7

    0 讨论(0)
提交回复
热议问题