While writing answers around SO, a user tried pointing out that java.io.File should not be used in new code, instead he argues that the the new object java.nio.Files should be used instead; he linked to this article.

在围绕SO编写答案时,用户试图指出不应该在新代码中使用java.io.File,而是认为应该使用新对象java.nio.Files;他链接到这篇文章。

Now I have been developing in Java for several years now, and have not heard this argument before; since reading his post I have been searching, and have not found many other sources that confirm this, and personally, I feel like many of the points argued in the article are weak and that if you know how to read them, errors thrown by the File class will generally tell you exactly what the issue is.

现在我已经用Java开发了好几年了,之前没有听过这个论点;自从阅读他的帖子以来我一直在寻找,并且没有找到许多证实这一点的其他来源,而且就个人而言,我觉得文章中提出的许多观点都很薄弱,如果你知道如何阅读它们,那么文件类通常会告诉您具体问题。

As I am continually developing new code my question is this:

当我不断开发新代码时,我的问题是:

Is this an active argument in the Java community? Is Files preferred over File for new code? What are the major advantages / disadvantages between the two?

这是Java社区中的一个活跃的参数吗?对于新代码,文件是否优先于文件?两者之间的主要优点/缺点是什么?

3 个解决方案

#1


12

The documentation that you linked give the answer:

您链接的文档给出了答案:

The java.nio.file package defines interfaces and classes for the Java virtual machine to access files, file attributes, and file systems. This API may be used to overcome many of the limitations of the java.io.File class. The toPath method may be used to obtain a Path that uses the abstract path represented by a File object to locate a file. The resulting Path may be used with the Files class to provide more efficient and extensive access to additional file operations, file attributes, and I/O exceptions to help diagnose errors when an operation on a file fails.

java.nio.file包定义Java虚拟机的接口和类,以访问文件,文件属性和文件系统。此API可用于克服java.io.File类的许多限制。 toPath方法可用于获取Path,该Path使用File对象表示的抽象路径来定位文件。生成的Path可以与Files类一起使用,以提供对其他文件操作,文件属性和I / O异常的更有效和广泛的访问,以帮助在文件操作失败时诊断错误。

更多相关文章

  1. 反编译APK 得到JAVA代码和资源文件源码
  2. JSP页面中有一个按钮 点击之后执行JAVA文件
  3. 如何在Java中递归解压缩文件?
  4. Java获得文件的创建时间(精确到秒)
  5. 拖动层的javasvript代码 十行代码即可写出兼容版拖动层
  6. 安卓Android文件上传Demo报错 java.io.FileNotFoundException: /
  7. Eclipse创建的包变成文件夹的解决方法
  8. 我无法让这个简单的ajax代码工作
  9. javascript实现拖动层效果代码(许愿墙)

随机推荐

  1. Java多线程之Thread、Runnable、Callable
  2. BufferedImage到InputStream - 格式不同
  3. 20145122《 Java网络编程》实验五实验报
  4. java操作ftp实现文件的上传下载(适用于图
  5. ***100分,谁有用java mail做的把表单直接
  6. 急求用jersey2.x+spring3.x 开发rest web
  7. 从AWS Lambda发布到SNS时超时
  8. Finder3.0 - 集群支持即将发布
  9. Java中的TreeMap、Comparable、Comparato
  10. 如何获得嵌入式Jetty Web服务器来转储其J