Java: FileOutputStream("NUL:") not working after Java upgrade

3.2k views Asked by At

On Windows, NUL is the null output device similar to /dev/null on Linux.

With Oracle Java 8 Update 331, trying to get a new FileOutputStream("NUL:") throws an exception. Previously (Java 8u321) it worked fine.

The problem seems to be the colon:

  • new FileOutputStream("NUL") - OK
  • new FileOutputStream("NUL:") - exception

Can anyone point me to docs or JDK sources regarding this change? I can't change the code itself because it is in a 3rd party lib (xnio-api).

try
{
  new FileOutputStream("NUL:");
  System.out.println("OK");
}
catch (FileNotFoundException e)
{
  System.out.println(e);
}
1

There are 1 answers

3
Joachim Sauer On BEST ANSWER

I suspect this is the offending change.

Apparently it tries to avoid accessing ADS (alternate data streams), but seems to "accidentally" also prevent access to device-files like this.

If that's correct, then you can try setting the system property jdk.io.File.enableADS to true to re-enable the old behaviour.