this is the font file under fonts folder in resources:
now, i want to get this file and use in CaptchaConfiguration
that is a spring configuration class, but cannot:
@Configuration
public class CaptchaConfiguration {
@Bean
public CaptchaService captchaService() {
WordGenerator wordGen = new RandomWordGenerator("123456789");
Font font;
try {
ClassPathResource res = new ClassPathResource("fonts/iranSans.ttf");
File fontFile = new File(res.getPath());
font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
}
catch (Exception e) {
e.printStackTrace();
font = new Font("Arial", Font.PLAIN, 10);
}
// ....
}
}
i also tested File fontFile = new File(getClass().getResource("fonts/iranSans.ttf").getFile())
, but didn't have any result and res
is null.