Questions tagged [nio2]

NIO2 is an umbrella name for new features added to the original Java NIO package in the Java 1.7 release. Also referred to as "New I/O".

NIO.2 is an umbrella name for new features added to the original Java package in the Java 1.7 release. Also referred to as "New I/O".

  • Asynchronous Channels and Futures: A Channel that supports asynchronous I/O operations with implementations for sockets, server sockets and files.
  • Completion Handlers: The ability to register handlers that will be called on the completion of an asynchronous I/O event.
  • Asynchronous Channel Groups: A grouping of asynchronous channels for the purpose of resource sharing.
  • Asynchronous Multicast: Support for implementing asynchronous NIO I/O with callbacks for UDP multicast.
  • A New File System API for Java: Defines new interfaces and classes for the Java virtual machine to access files, file attributes, and file systems.

Articles and Tutorials

Note: This tag and wiki should be rolled into the nio tag.

173 questions
0
votes
1 answer

How do i convert paths that contain unc shares

If user has not mounted a remote drive and is just using the \\ syntax how do I convert such a path (\\nas) held in a String to a file in Java, sorry not really sure what you call this \\ naming. Also is this windows specific, can it also be //
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
0
votes
1 answer

How do I sort results of File.listFiles() by creation date?

In Java Sort how do I sort results of File.listFiles() by creation date? I did have: files = reportFolder.listFiles(new ReportFolderFilter())); Collections.reverse(files); But this will only sort them in reverse alphabetical order not creation…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
0
votes
1 answer

Can I use NIO2 File Path for non-local file system schemas

I have been using NIO2 file paths for accessing local file system resources. However, when I try to use the same API for non-local file systems, then I get following exception: Exception in thread "main" java.nio.file.FileSystemNotFoundException: …
0
votes
0 answers

.getNameCount() different results when creating Path using String and URI

I am reading a book related to the OCP exam. I was studying about Path and URI and noticed something strange. Here is my code: URI u1 = new URI("file://C:/Brother/DrvLangChg/LangList.ini"); Path f =…
Phoenix
  • 15
  • 7
0
votes
0 answers

Why working on File's parent folder returns null or NoSuchFileException?

I want to get file's parent folder, list all of its files and return them as a Vector. Unfortunately, when I try to create a directory stream, I receive the NoSuchFileException. I'm a bit in a dark, because a few lines above I accessed that folder…
0
votes
0 answers

Files.setPosixFilePermissions NullPointerException

Using Oracle JDK 1.8.112 on RHEL 6.8, this is producing NullPointerException, on one system but not another: Files.setPosixFilePermissions(path, PosixFilePermissions.fromString("rwxrwxr-x")); But, this does not: PosixFileAttributeView av =…
wdkendall
  • 65
  • 1
  • 8
0
votes
0 answers

How to load a http .txt file as a Java FileSystem

I am studying for the Java 1.8 OCP exam and I ran across something in the Oracle study guide p.459 where it says you can load a remote URL as a FileSystem object. I tried this and can't get it to work. What is the simplest hello-world style…
djangofan
  • 28,471
  • 61
  • 196
  • 289
0
votes
1 answer

Trying to copy file and getting 'file does not exist' error

I am trying to copy files from 1 directory to another after re-naming them but keep getting the error: Exception in thread "main" java.nio.file.NoSuchFileException: C:\Users\talain\Desktop\marketingOriginal\FX…
Tom
  • 461
  • 1
  • 8
  • 24
0
votes
1 answer

Java NIO.2 CompletetionHandler not reaching

Java NIO.2 Gurus could anyone explain why this code not working when I'm commenting out the Thread.sleep(...) line. And what is the elegant way, to tell JVM to proccess asynchronous operations until program finishes? import…
theqavor
  • 3
  • 4
0
votes
0 answers

path1.resolve(path2) return path2 even path2.isAbsolute()=false and path2 is not empty

Given the following code Path p1 = Paths.get("\\photos\\vacation"); Path p2 = Paths.get("\\yellowstone"); System.out.println(p1.isAbsolute()); // false System.out.println(p2.isAbsolute()); // false …
psyskeptic
  • 286
  • 2
  • 4
  • 17
0
votes
0 answers

Counting files in Zip - java nio 2

How to count number files in an existing archive with java nio 2, without iterate. is a property like length() or size() exists ? Like : try (ZipFile zip = new ZipFile("my.zip")) { size = zip.size(); } Thanks
Mohammed
  • 89
  • 1
  • 3
  • 12
0
votes
0 answers

Does Tomcat8 NIO2 protocol support Apache CometEvent?

How can I set the comet event timeout on NIO2 protocol? How to well handle the socket connection on NIO2 protocol?(e.g., close connection) We have a simple servlet which implements Apache CometEvent for long polling connection on tomcat8. It works…
Bruce
  • 647
  • 2
  • 12
  • 30
0
votes
2 answers

MappedByteBuffer writing to file not working

I am having hard time understanding the read write with MappedByteBuffer. Here is the class I have that reads the content of a local file and suppose to reverse its content. I am using java version 8. public class MappedByteBufferExample { public…
Johnyzhub
  • 382
  • 2
  • 4
  • 18
0
votes
1 answer

Why can't I move non-empty directories across a drive using Files.move()?

Today I read in one 1z0-809 (OCP Java 8) preparation book that the Files.move() can be applied to non-empty directories only if they're on the same drive and that the moving a non-empty directory across a drive will throw a NIO.2…
frostman
  • 566
  • 2
  • 12
  • 25
0
votes
1 answer

AsynchronousSocketChannel not reading in entire message

When I run the below locally (on my own computer) it works fine - I can send messages to it and it reads them in properly. As soon as I put this on a remote server and send a message, only half the message gets read. try { …
Hooli
  • 1,135
  • 3
  • 19
  • 46