为什么Java没有文件副本?

时间:2022-04-10 07:18:54

Why does Java not have a file copy method? This seems like such an obvious thing to have, and it saves people from writing things like this example.

为什么Java没有文件复制方法?这似乎是一件显而易见的事情,它可以让人们免于编写像这样的例子。

4 个解决方案

#1


13  

The Java API is missing more than just file copying. You might be interested in checking out the Apache Commons libraries. For example, the IO library's FileUtils provides file copying methods.

Java API缺少的不仅仅是文件复制。您可能有兴趣查看Apache Commons库。例如,IO库的FileUtils提供了文件复制方法。

#2


7  

My guess is because when the File io system was written, they decided they did not want to deal with the cross-platform problems of copying files, and punted - i.e. they said "this is doable by others, and is not that common".

我的猜测是因为当编写File io系统时,他们认为他们不想处理复制文件的跨平台问题,并且受到惩罚 - 即他们说“这是其他人可行的,并不常见”。

One thing to keep in mind about Java is that it is cross-platform, so some things are more difficult because of that reality.

关于Java的一点要注意的是它是跨平台的,因此有些事情因为这个现实而变得更加困难。

#3


6  

java.io.File is a relatively simple class introduced in 1.0. JDK 1.0 didn't have much in it - mostly related to support for applets and the javac compiler. I guess there hasn't been a great deal of pressure to expand it - applets and enterprise software are not oriented in that direction.

java.io.File是1.0中引入的一个相对简单的类。 JDK 1.0没有太多内容 - 主要与支持applet和javac编译器有关。我想扩展它并没有太大的压力 - 小程序和企业软件并没有朝着这个方向发展。

However, lots has been added to I/O for JDK7. Including [java.nio.file.Path.copyTo][1].

但是,JDK7的I / O中添加了批量。包括[java.nio.file.Path.copyTo] [1]。

[1]: http://download.java.net/jdk7/docs/api/java/nio/file/Path.html#copyTo(java.nio.file.Path, java.nio.file.CopyOption...)

[1]:http://download.java.net/jdk7/docs/api/java/nio/file/Path.html#copyTo(java.nio.file.Path,java.nio.file.CopyOption ... )

#4


2  

For the same reason Java does not have many other things. which end up being implemented by external libraries. I am sure you can easily find such a library, or you can write a function.

出于同样的原因,Java没有很多其他的东西。最终由外部库实现。我相信你可以轻松找到这样的库,或者你可以编写一个函数。

#1


13  

The Java API is missing more than just file copying. You might be interested in checking out the Apache Commons libraries. For example, the IO library's FileUtils provides file copying methods.

Java API缺少的不仅仅是文件复制。您可能有兴趣查看Apache Commons库。例如,IO库的FileUtils提供了文件复制方法。

#2


7  

My guess is because when the File io system was written, they decided they did not want to deal with the cross-platform problems of copying files, and punted - i.e. they said "this is doable by others, and is not that common".

我的猜测是因为当编写File io系统时,他们认为他们不想处理复制文件的跨平台问题,并且受到惩罚 - 即他们说“这是其他人可行的,并不常见”。

One thing to keep in mind about Java is that it is cross-platform, so some things are more difficult because of that reality.

关于Java的一点要注意的是它是跨平台的,因此有些事情因为这个现实而变得更加困难。

#3


6  

java.io.File is a relatively simple class introduced in 1.0. JDK 1.0 didn't have much in it - mostly related to support for applets and the javac compiler. I guess there hasn't been a great deal of pressure to expand it - applets and enterprise software are not oriented in that direction.

java.io.File是1.0中引入的一个相对简单的类。 JDK 1.0没有太多内容 - 主要与支持applet和javac编译器有关。我想扩展它并没有太大的压力 - 小程序和企业软件并没有朝着这个方向发展。

However, lots has been added to I/O for JDK7. Including [java.nio.file.Path.copyTo][1].

但是,JDK7的I / O中添加了批量。包括[java.nio.file.Path.copyTo] [1]。

[1]: http://download.java.net/jdk7/docs/api/java/nio/file/Path.html#copyTo(java.nio.file.Path, java.nio.file.CopyOption...)

[1]:http://download.java.net/jdk7/docs/api/java/nio/file/Path.html#copyTo(java.nio.file.Path,java.nio.file.CopyOption ... )

#4


2  

For the same reason Java does not have many other things. which end up being implemented by external libraries. I am sure you can easily find such a library, or you can write a function.

出于同样的原因,Java没有很多其他的东西。最终由外部库实现。我相信你可以轻松找到这样的库,或者你可以编写一个函数。