简体   繁体   中英

How to get path to save a file from user?

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 select a file from the existing files whereas I want to save. What can be the way? Please give me some brief description.

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.

您可以在此处找到有关FileChooser的完整示例

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

您是否尝试过JFileChooser的showSaveDialog()方法?

Is there a JDirectoryChooser. Sounds to easy!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM