刻录到磁盘后无法加载字体
我有一个应用程序,其字体存储在 jar 文件中。它加载了:
public Font getChessFont()
{
InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("fonts\\MERIFONTNEW.TTF");
Font toReturn;
try
{
toReturn = Font.createFont(Font.TRUETYPE_FONT, in);
}
catch (Exception e)
{
toReturn = gameInformation;
}
toReturn = toReturn.deriveFont(Font.PLAIN, squareSize);
return toReturn;
}
当从 Eclipse 或 jar 文件运行程序时,此代码成功加载字体。但是,当我将 jar 文件放入 ISO 映像并将其挂载到磁盘后,文件无法加载。关于我做错了什么有什么想法吗?
I have an application which has a font stored within a jar file. It is loaded with:
public Font getChessFont()
{
InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("fonts\\MERIFONTNEW.TTF");
Font toReturn;
try
{
toReturn = Font.createFont(Font.TRUETYPE_FONT, in);
}
catch (Exception e)
{
toReturn = gameInformation;
}
toReturn = toReturn.deriveFont(Font.PLAIN, squareSize);
return toReturn;
}
When running the program from Eclipse or a jar file this code loads the font sucessfuly. However, after I put the jar files into an ISO image and mount them to a disk the files fail to load. Any ideas as to what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然我的评论足以解决这个问题。所以这个问题可以“回答”,我添加了评论作为答案:
资源路径通常应该在路径中使用正斜杠(/)(更像是 URL),因为这是独立于平台的。
Apparently my comment was enough to solve this. So the question can be "answered", I have added the comment as an answer:
Resource paths usually should use forward slash (/) in the path (more like a URL) as this is platform independent.
磁盘上的文件/JAR 是否位于类路径中?
Are the files/JARs on the disk on the classpath?