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");