开发者

Java issue with saving file with new name

开发者 https://www.devze.com 2023-02-28 05:52 出处:网络
I am writing a pr开发者_如何学Pythonogram whch requires me to save a BufferedImage with a new name. I can get the save dialog and stuff to work. I can even save the file with the same name it had befo

I am writing a pr开发者_如何学Pythonogram whch requires me to save a BufferedImage with a new name. I can get the save dialog and stuff to work. I can even save the file with the same name it had before. I just can't figure out how a user can enter a new name in the save dialog and have the file saved under that name. Please help?


Something like this?

JFileChooser chooser = new JFileChooser();
if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION)
    ImageIO.write(img, "png", chooser.getSelectedFile());


Read JFileChooser's getSelectedFile() method javadoc carefully.

Quoting:

Returns the selected file. This can be set either by the programmer via setFile or by a user action, such as either typing the filename into the UI or selecting the file from a list in the UI.

0

精彩评论

暂无评论...
验证码 换一张
取 消