Java - How to change icon of folder

大憨熊 提交于 2019-12-17 20:40:07

问题


So how do I change the icon of a folder in Java (Windows system) is there a class or something cause I have searched and I can't find anything...


回答1:


Based on the comments, the folder icon that you are talking about is specified in a hidden "ini" file in the folder itself.

You could create / modify the file by reading it as text, etcera, but it is simpler to use an existing 3rd-party Java library. I've had success using the open-source ini4j Java library.




回答2:


I did that using ini4J and It is working with me under only one condition : Folder path shouldn't have any space.

The Code:

// Create destop.ini file 
writer = new BufferedWriter("your folder path without any spaces");
writer.write("");
writer.close();

// Set file attributes hidden and system and set folder as system folder and not hidden
Wini ini = new Wini("your folder path without any spaces");
String field = "icon Path" + ",0";
ini.put(".ShellClassInfo", "IconResource", field);
ini.store();
Process processCreateFile = Runtime.getRuntime().exec("attrib +h +s " + "desktop.ini file path");
Process processCreateFolder = Runtime.getRuntime().exec("attrib -h +s " + "your folder path without any spaces");


来源:https://stackoverflow.com/questions/9330512/java-how-to-change-icon-of-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!