Using Java nio to create a subdirectory and file

You could declare your confFile as File instead of Path. Then you can use confFile.getParentFile().mkdirs();, see example below: // … File confFile = new File(“./conf/conf.xml”); confFile.getParentFile().mkdirs(); // … Or, using your code as is, you can use: Files.createDirectories(confFile.getParent());

Create a ByteBuf in Netty 4.0

The documentation seems pretty clear to me: Creation of a buffer It is recommended to create a new buffer using the helper methods in Unpooled rather than calling an individual implementation’s constructor. Then in Unpooled, you’ve got options of wrapping or copying. For example: Unpooled.copiedBuffer(ByteBuffer) Unpooled.copiedBuffer(byte[]) Unpooled.wrappedBuffer(ByteBuffer) Unpooled.wrappedBuffer(byte[]) Choose whichever method is appropriate based on … Read more

Java WatchService not generating events while watching mapped drives

I have the same issue trying to watch a mounted windows share via CIFS. It seems not possible to get filesystem events for CIFS mounts. The linux implementation of the Java 7 NIO FileWatcher uses inotify. Inotify is a linux kernel subsystem to notice filesystem changes which works perfect for local directories, but apparently not … Read more

Why the odd performance curve differential between ByteBuffer.allocate() and ByteBuffer.allocateDirect()

How ByteBuffer works and why Direct (Byte)Buffers are the only truly useful now. first I am a bit surprised it’s not common knowledge but bear it w/ me Direct byte buffers allocate an address outside the java heap. This is utmost importance: all OS (and native C) functions can utilize that address w/o locking the … Read more

java.nio.file.Path for URLs?

It seems like what you’re really trying to do is accomplish what FTP does – copy files from one place to another. I would suggest you find better ways to do this with existing FTP code libraries. URIs are not file system paths, so you can’t treat them as such. They are addresses/resource locators that, … Read more

java.io.File vs java.nio.Files which is the preferred in new code?

The documentation that you linked give the answer: The java.nio.file package defines interfaces and classes for the Java virtual machine to access files, file attributes, and file systems. This API may be used to overcome many of the limitations of the java.io.File class. The toPath method may be used to obtain a Path that uses … Read more