Skip to content
Advertisement

Tag: nio

Moving files from one directory to another with Java NIO

I am using the NIO libraries but I am getting a strange error when I try to move files from one directory to another. Iterate over elements that start with “2014” and move them in the new directory (newDir, which is also called 2014) I get the java.nio.file.FileAlreadyExistsException because my folder (2014) already exists. What I actually want to do

Using Java nio to create a subdirectory and file

I’m creating a simple program that will try to read in “conf/conf.xml” from disk, but if this file or dir doesn’t exist will instead create them. I can do this using the following code: My questions is if this really the most elegant way to do this? It seems superflous to need to create two Paths simple to create a

When to use ** (double star) in glob syntax within JAVA

Directly from this Java Oracle tutorial: Two asterisks, **, works like * but crosses directory boundaries. This syntax is generally used for matching complete paths. Could anybody do a real example out of it? What do they mean with “crosses directory boundary”? Crossing the directory boundary, I imagine something like checking the file from root to getNameCount()-1. Again a real

How to access a sub-file/folder in Java 7 java.nio.file.Path?

Java 7 introduced java.nio.file.Path as a possible replacement for java.io.File. With File, when I access a file under a specific, I would do: What’s the way to do this with Path? I supposed this will work: But calling parent.toString() seems ugly. Is there a better way? Answer Use the resolve method on Path. There are two methods with this name.

SocketChannel: Single or multi , which is better?

SocketChannel is thread safe, so only one channel is need for communication between client and server. the channel served for read/write operations simultaneously But, if we using multi channels (more than one connections between the same client and server), will the io performance be improved ??? If can, why?????? any answer is welcome. Suppose a cache client, which poll data

Java Large Files Disk IO Performance

I have two (2GB each) files on my harddisk and want to compare them with each other: Copying the original files with Windows explorer takes approx. 2-4 minutes (that is reading and writing – on the same physical and logical disk). Reading with java.io.FileInputStream twice and comparing the byte arrays on a byte per byte basis takes 20+ minutes. java.io.BufferedInputStream

Advertisement