Wednesday 15 February 2012

java - On OSX and JVM 7, FileChannel.open seems to be broken -



java - On OSX and JVM 7, FileChannel.open seems to be broken -

on osx jvm 7, seeing filechannel.open create_new doesn't seem comply docs. code below, expect create new file, , fail if can't (permissions, disk issue) or file exists.

scala> filechannel.open(new file("/tmp/doesnotexist").topath, standardopenoption.create_new) java.nio.file.nosuchfileexception: /tmp/doesnotexist @ sun.nio.fs.unixexception.translatetoioexception(unixexception.java:86) @ sun.nio.fs.unixexception.rethrowasioexception(unixexception.java:102) @ sun.nio.fs.unixexception.rethrowasioexception(unixexception.java:107) @ sun.nio.fs.unixfilesystemprovider.newfilechannel(unixfilesystemprovider.java:177) @ java.nio.channels.filechannel.open(filechannel.java:287) @ 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 = sun.nio.ch.filechannelimpl@19fed8d0 scala> filechannel.open(path.topath, standardopenoption.create_new) res11: java.nio.channels.filechannel = sun.nio.ch.filechannelimpl@5c6ff75 scala> filechannel.open(path.topath, standardopenoption.create_new) res12: java.nio.channels.filechannel = sun.nio.ch.filechannelimpl@1fa547d1

here java using

$ 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)

is doc (or interpretation of doc) issue, or bug on osx (maybe linux? not tested yet)?

you must specify write along create_new. tested on os x you, , works expected:

filechannel.open(paths.get("/tmp/doesnotexist"), standardopenoption.create_new, standardopenoption.write);

java osx jvm

No comments:

Post a Comment