Java 7:路径与文件 [英] Java 7: Path vs File

查看:168
本文介绍了Java 7:路径与文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于使用Java 7编写的新应用程序,是否有任何理由使用 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

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

这篇关于Java 7:路径与文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆