I have a FileOutputStream. I want to "save" this file and give it a own icon that is saved in the ressource-folder.
Here's the code:
ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream(path));
oout.writeObject(this.categoryDAO);
oout.writeObject(this.toDoDAO);
oout.flush();
oout.close();
In the "path"-variable is the whole path including filename. I want the icon for that file.
Is it possible to set a own icon or do I have to do it with otherwise?
No, you can't do this just from Java.
Icons are associated with a file extension, so if the file ends with '.txt', then it might show a page, while an image with '.jpg' will show a thumbnail or a picture icon.
This is built in at the OS level. Whenever you install new applications, they tell the OS what extensions they can handle. When the OS shows you files in your explorer, it looks at the list of applications that can handle the extension, and shows the appropriate icon.
If you want a specific icon, you can register your own specific file extension, and when you save your files in Java, use that extension. The exact details of how to do that are OS dependent, and not related to Java, so out of the scope of this answer.