Font.createFont leaves files in temp directory

The code below does its job, but leaves a copy of the font file in the temp directory every time it starts. These files are called + ~ JF7154903081130224445.tmp, where the number seems random for each file created.

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

I found many years of discussion on forums on sun.com and other resources on the Internet where it is recognized as a bug in the JDK, where updating from 1.5.0_06 to 1.5.0_08 will solve the problem; however, the version I'm using is a later version (1.6.0_13).

I tried to solve the problem by deleting the files after completing the operations related to the font, but the files were locked at this time. Files can only be deleted after the web application is stopped.

Does anyone have a solution?

+7
java fonts graphics2d temporary-files
source share
2 answers

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

As far as I know, this error exists in Java 6, just look at the sources of the Font class.

+1
source share

With JDK1.6.0_16, the font manager seems to use the temporary file as a kind of cache and will only read glyphs from the font when needed. It also adds a stop hook that will delete the file when the JVM usually ends. Depending on the virtual machine, font rendering may also be transferred to its own code, which needs access to the file, so preserving the file lock seems reasonable to me.

Are the files actually saved even if your servlet container (you mention the web application) ends regularly or you kill it, preventing it from clearing its resources correctly?

+1
source share

All Articles