We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
报错代码:com.pig4cloud.captcha.utils.FontsUtil.getFont。
/** * 手动复制字体文件到临时目录. 调用传文件的构造方法创建字体 * @param fontName 字体文件名称 * @return */ public static Font getFont(String fontName, int style, float size) { Font font = null; String path = System.getProperty("java.io.tmpdir"); File tempFontFile = new File(path + fontName); if(!tempFontFile.exists()){ //临时文件不存在 copyTempFontFile(fontName, tempFontFile); } if(tempFontFile.exists()) { try { font = Font.createFont(Font.TRUETYPE_FONT, tempFontFile).deriveFont(style, size);; } catch (FontFormatException | IOException e) { e.printStackTrace(); tempFontFile.delete(); } } return font; }
上面代码使用System.getProperty("java.io.tmpdir")获取临时目录路径时,在Windows上获取的路径大概如下C:\Users\XXX\AppData\Local\Temp\
System.getProperty("java.io.tmpdir")
C:\Users\XXX\AppData\Local\Temp\
此时拼接的字体文件路径无误:C:\Users\XXX\AppData\Local\Temp\actionj.ttf
C:\Users\XXX\AppData\Local\Temp\actionj.ttf
但是在Linux上获取的临时目录为:/tmp,后面并没有带文件夹分隔符,这导致拼接出来的字体文件路径出错,类似这样:/tmpactionj.ttf
/tmp
/tmpactionj.ttf
这样在拷贝字体时会报错:
java.io.FileNotFoundException: /tmpactionj.ttf (Permission denied) at java.base/java.io.FileOutputStream.open0(Native Method) at java.base/java.io.FileOutputStream.open(FileOutputStream.java:289) at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:230) at com.pig4cloud.captcha.utils.FileUtil.openOutputStream(FileUtil.java:37) at com.pig4cloud.captcha.utils.FileUtil.openOutputStream(FileUtil.java:26) at com.pig4cloud.captcha.utils.FileUtil.copyToFile(FileUtil.java:20) at com.pig4cloud.captcha.utils.FontsUtil.copyTempFontFile(FontsUtil.java:65) at com.pig4cloud.captcha.utils.FontsUtil.getFont(FontsUtil.java:45) at com.pig4cloud.captcha.base.Captcha.setFont(Captcha.java:299) at com.pig4cloud.captcha.base.Captcha.setFont(Captcha.java:295) at com.pig4cloud.captcha.base.Captcha.setFont(Captcha.java:291) at com.pig4cloud.captcha.base.Captcha.getFont(Captcha.java:277)
希望作者大大能够在代码后面加一段判断是否有文件夹分隔符的逻辑。
The text was updated successfully, but these errors were encountered:
虽然可以通过加命令行参数的方式解决,但多少还是只能算临时方案。希望作者能修复这个问题。
Sorry, something went wrong.
No branches or pull requests
报错代码:com.pig4cloud.captcha.utils.FontsUtil.getFont。
上面代码使用
System.getProperty("java.io.tmpdir")
获取临时目录路径时,在Windows上获取的路径大概如下C:\Users\XXX\AppData\Local\Temp\
此时拼接的字体文件路径无误:
C:\Users\XXX\AppData\Local\Temp\actionj.ttf
但是在Linux上获取的临时目录为:
/tmp
,后面并没有带文件夹分隔符,这导致拼接出来的字体文件路径出错,类似这样:/tmpactionj.ttf
这样在拷贝字体时会报错:
希望作者大大能够在代码后面加一段判断是否有文件夹分隔符的逻辑。
The text was updated successfully, but these errors were encountered: