Java - How to change icon of folder

2020-02-06 16:50发布

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...

2条回答
在下西门庆
2楼-- · 2020-02-06 17:18

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");
查看更多
家丑人穷心不美
3楼-- · 2020-02-06 17:32

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.

查看更多
登录 后发表回答