You can get URL and a URI but remember that both of them work differently.
The URL encode the string where the URI is the actual resource.
I had a problem in a Java unit test (using jUnit) for PDFTable where my unit test failed since it was unable to load the fonts. The reason for this is that it was using the URL so trying to find the font files under an encoding path.
So the actual code fix is:
URI url = getClass().getClassLoader().getResource(fontResourceDir).toURI();
String path = url.getPath();
The toURI() method represents this abstract pathname.