

What's New In Java 7: Copy and Move Files and Directories - mindcrime
http://codingjunkie.net/java-7-copy-move

======
waffle_ss
Another new feature in Java 7 is the WatchService API[1], which allows one to
watch a directory for file changes (implemented using native filesystem
methods). Previously, this could only be done with polling[2] or custom native
code called through JNI.

[1]:
[http://docs.oracle.com/javase/tutorial/essential/io/notifica...](http://docs.oracle.com/javase/tutorial/essential/io/notification.html)
[2]: <http://jnotify.sourceforge.net/>

~~~
moonchrome
How is Java7 API not using polling ? You create a watch service and then you
call poll on it to get update events - or am I missing something ?

~~~
arethuza
Do you mean pooling or polling?

~~~
moonchrome
My error - corrected (intellisense keeps you ignorant about these
errors/english isn't my first language so it doesn't sound strange :))

------
pooriaazimi
I've been living under a rock(1) and haven't heard about all those new
additions in Java 7:

> _The additions with this release are useful, for example Try with resources
> – having closable resources handled automatically from try blocks, Strings
> in switch statements, multicatch for Exceptions and the ‘ <>‘ operator for
> working with generics._

Just copied them from <http://codingjunkie.net/java7-file-revolution/>, for
the benefit of other lazy, under-rock-living ones.

(1): not really - But when I read
<http://news.ycombinator.com/item?id=2820204> this summer, I closed my ears to
all Jave 7 news (which admittedly was foolish).

------
6ren
I've been playing with CoffeeScript and Ruby lately, and was very weirded out
by the lack of parentheses in method calls, til I started to see them as bash-
like (but more sophisticated of course), where you just add the arguments.
Ruby used to be called a "scripting" language after all.

Another characteristic of "scripting" languages is ease of file handling. Java
is not a scripting language. Previously, if you wanted to copy from one stream
to another, you had to write a loop (maybe you still do, and this "copy" is
strictly for files?). Simple; but nice if they provided a _cat()_ method. It's
quite amazing how popular Java is (and how useful it must be in other areas),
considering this kind of trivial shortcoming.

~~~
alt_
NIO FileChannels have a transferTo() method[1]. I expect they only added it
once they found a good enough reason (zero-copy). The standardization process
moves so slow that convenience functions are better served by third-party
libraries.

[1]
[http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/channe...](http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/channels/FileChannel.html#transferTo\(long,%20long,%20java.nio.channels.WritableByteChannel\))

------
RandallBrown
Wait, you couldn't copy or move files with Java until now? Are there really no
java applications that move or copy files?

~~~
DanielRibeiro
Of course you could. It was an awful api:
<http://docs.oracle.com/javase/6/docs/api/java/io/File.html>

This is why people used Apache FileUtils:
[http://commons.apache.org/io/apidocs/org/apache/commons/io/F...](http://commons.apache.org/io/apidocs/org/apache/commons/io/FileUtils.html)

On java 7 a better api is only part of the _standard_ library.

~~~
afsina
No it could not copy directly until Java7. Sure there was a million helper
class could do this. but not the main SDK.

