简体   繁体   中英

How to load embedded font as InputStream from jar in java?

If I run the application from Eclipse, then all be done. But If export it to jar i get an Exception.

java.io.IOException: Problem reading font data.
at java.awt.Font.createFont(Unknown Source)

Here is the package tree

在此输入图像描述

And my code (In the SzervizPrint.java file):

InputStream istream = getClass().getResourceAsStream("/resources/SerpentineBolditalic.ttf");
Font myFont = Font.createFont(Font.TRUETYPE_FONT, istream);
myFont = myFont.deriveFont(36.0f);
lblNewLabel.setFont(myFont);
SerpentineBolditalic.ttf

Should be:

SerpentineBoldItalic.ttf 

(capital 'I')

While the local file system might not be case sensitive, getResource(String) most definitely is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM