简体   繁体   中英

Why doesn't Java have a file copy?

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 .

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.

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 - ie they said "this is doable by others, and is not that common".

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.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.

However, lots has been added to I/O for JDK7. Including [ 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...)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM