You get this exception because you use the new File(myURI) , and myURI has a difference scheme than file:
For example, this will work (note the file: // ...):
System.out.println(new File(new URI("file:///etc/passwd")));
whereas it does not work (note http: // ...):
System.out.println(new File(new URI("http://localhost/etc/passwd")));
If you want to use the getResource() method, you need to work with the URL. You cannot assume that it will always have a file: scheme.
If you need to create a Font from a * .ttf resource file, you can do:
URL url = this.getClass().getResource("/fonts/ARIALUNI.TTF"); InputStream is = url.openStream(); Font font = Font.createFont(Font.TRUETYPE_FONT, is);
source share