Search code examples
javafontsclassloaderisotruetype

Failing to load font after burning to disk


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?


Solution

  • 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.