how would i add an icon to my save file?
right now, i can save a file using JFileChooser, but how would i added an icon to the file that i saved?
fileChooser.addChoosableFileFilter(new CLVFilter());
int returnValue = fileChooser.showSaveDialog(frame);
if(returnValue == JFileChooser.APPROVE_OPTION){
try{
//filename consists of path
String filename = fileChooser.getSelectedFile().toString();
FileWriter fstream = new开发者_StackOverflow FileWriter(filename);
BufferedWriter out = new BufferedWriter(fstream);
out.write(SingleIntersection.this.getContentsOfObject());
out.close();
}catch (Exception excep){//Catch exception if any
System.err.println("Error: " + excep.getMessage());
}
}
An icon is something your operating system displays (as mentioned by Andy Thomas-Cramer). All you need to specify is the file extension while creating the file.
The file icon is dependent on the file type. This association (type-icon) is done by the operating system (in windows it depends on the file name extension). You may change the association with java code, but not the icon of a specific file.
If you are on OSX, you should also look at the Apple Java Extensions, specifically FileManager. Calling setFileType(int)
may get you the desired results.
Unfortunately, I don't know of any non-JNI way to write to the Resource Fork.
We have to set a icon file using windows registry.
eg : your extension .expr
then create icon file for this using registry.
精彩评论