Skip to content
Advertisement

Java: FileOutputStream(“NUL:”) not working after Java upgrade

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);
}

Advertisement

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.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement