Su OSX con JVM 7, vedo che FileChannel.open con CREATE_NEW non sembra essere conforme allo docs. Il codice qui sotto, mi aspetterei di creare un nuovo file, e fallirebbe solo se non fosse possibile (autorizzazioni, problema del disco) o che il file esistesse già.Su OSX e JVM 7, FileChannel.open sembra essere rotto
scala> FileChannel.open(new File("/tmp/doesnotexist").toPath, StandardOpenOption.CREATE_NEW)
java.nio.file.NoSuchFileException: /tmp/doesnotexist
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:177)
at java.nio.channels.FileChannel.open(FileChannel.java:287)
at java.nio.channels.FileChannel.open(FileChannel.java:334)
... 32 elided
scala> val path = new File("/tmp/doesnotexist")
path: java.io.File = /tmp/doesnotexist
scala> path.createNewFile()
res9: Boolean = true
scala> FileChannel.open(path.toPath, StandardOpenOption.CREATE_NEW)
res10: java.nio.channels.FileChannel = [email protected]
scala> FileChannel.open(path.toPath, StandardOpenOption.CREATE_NEW)
res11: java.nio.channels.FileChannel = [email protected]
scala> FileChannel.open(path.toPath, StandardOpenOption.CREATE_NEW)
res12: java.nio.channels.FileChannel = [email protected]
Ecco la Java che sto usando
$ java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
Si tratta di un documento (o l'interpretazione del doc) problema, o di un bug su OSX (forse anche Linux? Non ancora testato)?
Grazie, ha funzionato! – ekaqu