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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…