How to open "Save As" in a Java application?

Asked

Viewed 200 times

-3

I am trying to create an application that takes a user input stores in a variable and saves the input in a directory informed by it through the "save as" windows, but I can only access the file explorer and not a "save as" window (same in print)there is some way to do this?

import java.io.IOException;
import java.util.Scanner;

public class Runtimetest {
    public static void main(String[] args) throws IOException {
        Scanner input = new Scanner(System.in);
        String texto = input.nextLine();
        Runtime.getRuntime().exec("explorer.exe");
    }
}   

Salvar como

1 answer

2


What you are invoking in Runtime runs the "explorer.exe" which is no longer the same Windows file explorer. Generally, you send as parameters in which directory you want to save the file.

What you can do is use Swing and create your structure using File Chooser.

In the link below you have an implementation:

http://www.java2s.com/Code/Java/Swing-JFC/DemonstrationofFiledialogboxes.htm

Browser other questions tagged

You are not signed in. Login or sign up in order to post.