我如何将图标添加到我的保存文件中?
现在,我可以使用 JFileChooser 保存文件,但是如何向我保存的文件添加图标?
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 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());
}
}
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 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());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
图标是操作系统显示的东西(如 Andy Thomas-Cramer 所提到的)。您需要在创建文件时指定文件扩展名。
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.
文件图标取决于文件类型。这种关联(类型图标)由操作系统完成(在 Windows 中,它取决于文件扩展名)。 您可以更改与 java 代码的关联,但不能更改一个特定的文件。
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.
如果您使用的是 OSX,您还应该查看 Apple Java 扩展,特别是 文件管理器。调用 setFileType(int) 可能会得到您想要的结果。
不幸的是,我不知道有什么非 JNI 方式写入到资源分叉。
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.
我们必须使用 Windows 注册表设置一个图标文件。
例如:您的扩展名 .expr
然后使用注册表为此创建图标文件。
We have to set a icon file using windows registry.
eg : your extension .expr
then create icon file for this using registry.