Font.createFont将文件保存在临时目录中 [英] Font.createFont leaves files in temp directory

查看:661
本文介绍了Font.createFont将文件保存在临时目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码完成了它的工作,但是每次运行时都会将字体文件的副本保留在临时目录中。这些文件被命名为 +〜JF7154903081130224445.tmp ,其中每个创建的文件的编号似乎是随机的。

InputStream fontStream = this.getClass()。getResourceAsStream(handsean.ttf);
字体baseFont = Font.createFont(Font.TRUETYPE_FONT,fontStream);
fontStream.close();

我在sun.com和其他资源网站上发现了多年的讨论,在JDK中被认为是一个bug,从1.5.0_06升级到1.5.0_08将解决问题;然而,我使用的版本是一个更高版本(1.6.0_13)。

我试图通过删除字体相关的操作完成后的文件解决问题,但当时文件被锁定。
这些文件只能在Web应用程序停止后才能被删除。

有没有人可以解决这个问题?


据我所知,这个bug存在于Java 6中,查看Font类的来源就足够了。


The code below does its work but leaves copies of the font file in the temp directory each time it is run. These files are named +~JF7154903081130224445.tmp where the number seems random for each created file.

InputStream fontStream = this.getClass().getResourceAsStream("handsean.ttf");
Font baseFont = Font.createFont(Font.TRUETYPE_FONT, fontStream);
fontStream.close();

I have found years-old discussions in forums at sun.com and other resources on the web where this is recognized as a bug in JDK, where upgrading from 1.5.0_06 to 1.5.0_08 would solve the problem; however, the version I am using is a later version (1.6.0_13).

I tried solving the problem by deleting the files after the font related operations are finished, but the files are locked at that time. The files can only be deleted after the web application has stopped.

Does anybody have a solution to this?

解决方案

If your ttf files are not inside an archive, you can call createFont(File) instead of createFont(InputStream)

As to the best of my knowledge, this bug exists in Java 6, it is enough to look at the sources of Font class.

这篇关于Font.createFont将文件保存在临时目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆