开发者

How to get path to save a file from user?

开发者 https://www.devze.com 2022-12-18 16:21 出处:网络
I\'m developing an application in which I want to create an \'MS-EXCEL\' file and for that I want the name for the file to be given by user and later on I want to provide an option to the user to save

I'm developing an application in which I want to create an 'MS-EXCEL' file and for that I want the name for the file to be given by user and later on I want to provide an option to the user to save at the path where it wants. I know about JFileChooser but it only allows to 开发者_C百科select a file from the existing files whereas I want to save. What can be the way? Please give me some brief description.


A full example on FileChooser you find here


You can use JFileChooser.setFileSelectionMode to allow selection of either files, directories, or both files and directories.

You can also type in the name of a file that doesn't already exist.


    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int option = chooser.showSaveDialog(null);
    if (option == JFileChooser.APPROVE_OPTION)
    {
        // do soemthing
    }


Have you tried the JFileChooser's showSaveDialog() method?


Is there a JDirectoryChooser. Sounds to easy!

0

精彩评论

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