[英]Font File Won't Delete
I'm trying to install PhpStorm and after a long story it looks like I have some bad fonts getting in the way of Java. 我正在尝试安装PhpStorm,经过一番长话,看来我的Java遇到了一些不良字体。
I'm completely new to Java but I found this code to loop through my fonts and find the bad ones. 我是Java的新手,但是我发现这段代码可以遍历我的字体并找到错误的字体。 I've modified it to delete the bad font, but it won't delete.
我已经对其进行了修改,以删除错误的字体,但不会删除。
import java.io.File;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
public class myFontCheck {
public static void main(String[] args) {
Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for (int i = 0; i < fonts.length; i++) {
final Font font = fonts[i];
final String name = font.getFontName();
if (font.canDisplay('a') &&
font.canDisplay('z') &&
font.canDisplay('A') &&
font.canDisplay('Z') &&
font.canDisplay('0') &&
font.canDisplay('1')) {
//System.out.println(" OK.");
} else {
File file = new File("c:\\Windows\\Fonts\\" + name + ".ttf");
if(file.exists()) {
System.out.println("Bad Font: " + name);
file.delete();
}
}
}
}
}
I'm assuming it's a file permission conflict but I can't figure out how to change the permissions. 我假设这是文件权限冲突,但我不知道如何更改权限。 Do I need to run this as an administrator?
我需要以管理员身份运行吗?
Or.. can you show me how to open just the bad files into an explorer window so that I can 'Select All'? 或者..您能告诉我如何将不良文件仅打开到资源管理器窗口中,以便我可以“全选”吗?
if (font.canDisplay('a') &&
font.canDisplay('z') &&
font.canDisplay('A') &&
font.canDisplay('Z') &&
font.canDisplay('0') &&
font.canDisplay('1')) {
//System.out.println(" OK.");
} else {
System.out.println("Bad Font: " + name);
File file = new File("c:\\Windows\\Fonts\\" + name + ".ttf");
file.delete();
}
Uncomment the "bad fonts line". 取消注释“不良字体行”。 Does anything get printed out when you run the app?
运行该应用程序时,是否打印任何内容? I suspect no, because although you might not like the way the font displays, canDisplay might return true.
我怀疑没有,因为尽管您可能不喜欢字体的显示方式,但是canDisplay可能会返回true。
Alternatively, the "new File", string construction might result in something incorrect. 或者,“新文件”字符串构造可能会导致某些错误。 I would try printing that out as well, and checking the file system for that file.
我也会尝试将其打印出来,并检查该文件的文件系统。
Sort of like this: 有点像这样:
} else {
System.out.println("Bad Font: " + name);
String fn = "c:\\Windows\\Fonts\\" + name + ".ttf";
System.out.println("Trying to delete: " + fn);
File file = new File(fn);
file.delete();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.