Assuming you have a package structure in your application like this

The following code should work
import java.io.InputStream;
import javafx.scene.text.Font;
public class AccessTest {
public static void main(String[] args) throws URISyntaxException, MalformedURLException {
InputStream is = AccessTest.class.getResourceAsStream("OpenSans-Regular.ttf");
Font font = Font.loadFont(is, 12.0);
System.out.println("Font: " +font);
File f = new File(AccessTest.class.getResource("OpenSans-Regular.ttf").toURI());
// should not be used because of f.toURL() is deprecated
Font font1 = Font.loadFont(f.toURL().toExternalForm(), 12.0);
System.out.println("Font 1: " + font1);
Font font2 = Font.loadFont(f.toURI().toURL().toExternalForm(), 12.0);
System.out.println("Font 2: " + font2);
}
}
This gives me the following output:
Font: Font[name=Open Sans, family=Open Sans, style=Regular, size=12.0]
Font 1: Font[name=Open Sans, family=Open Sans, style=Regular, size=12.0]
Font 2: Font[name=Open Sans, family=Open Sans, style=Regular, size=12.0]
If you put the font file outside of your package there could be an access violation. In your case the Font.load() method simply breaks in construction a suitable Inputstream. It could be a bit tricky to get the suitable URL or URI that the load method uses.