Search code examples
javaeclipsefontsdrjava

Cant import Font in Eclipse but can import in Dr. Java


So i have this code

File fontFile = new File("FrizQuadrataTT.ttf");;
FileInputStream in = new FileInputStream(f);
Font dFont = Font.createFont(Font.TRUETYPE_FONT, in);
Font f1 = dFont.deriveFont(15f);

Which import a font file called FrizQuadrataTT.ttf. I used to use Dr. Java to code and i recently started to use Eclipse but now in eclipse this code doesn't work. It does however work in Dr. Java.

Exception in thread "main" java.io.FileNotFoundException: FrizQuadrataTT.ttf (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)

This is the error message that is given when run.


Solution

  • The file must be in your application's classpath. I believe that Eclipse will add the project's root directory to the classpath automatically, so you should just put FrizQuadrataTT.ttf directly into the project's root directory.