开发者

Java issue with saving file with new name

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜