1. 程式人生 > 實用技巧 >java: 讀取字型檔案(ttf, ...)中的字型名

java: 讀取字型檔案(ttf, ...)中的字型名

int i = 101;        
        
        File[] fileList = new File("E:\\fonts2").listFiles();
        for(File f:fileList)
        {
            //System.out.println(f);
            
            String fileName = f.getName();
            int index = fileName.lastIndexOf(".");            
            
            String path 
= "e:\\fonts\\" + i + fileName.substring(index); //System.out.println(fontName + " ---> " + path); i++; Font f2; try { f2 = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(f.getAbsoluteFile())); String fontName
= f2.getName(); System.out.println(f.getName() + " ---> 字型名:" + fontName); System.err.println("hashmap_put(fontFileMap, strdup(\"" + fontName + "\"), strdup(\"" + path.replace("\\", "\\\\") + "\"));");
//Files.copy(f.toPath(), new File(path).toPath()); //把檔案複製一份到另一個資料夾 } catch (Exception e) { e.printStackTrace(); } } System.exit(0);

參考:https://bbs.csdn.net/topics/390161351