URLs with spaces in them are invalid. The correct way to create a properly encoded URL from a filename that may contain spaces is URI.toASCIIString(),
and then passing that to new URL(),
making sure to use a URI constructor that takes multiple arguments so the filename part gets encoded: see the Javadoc.
However I question the requirement. The best way to test whether any resource is available is to try to use it. In this case presumably you are going to read from the URL if it exists, so just do that and catch the FileNotFoundException
.