File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes In JFileDialog how to use the save window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "In JFileDialog how to use the save window " Watch "In JFileDialog how to use the save window " New topic

In JFileDialog how to use the save window

sushant prabhu
Ranch Hand

Joined: Mar 22, 2001
Posts: 66
I have used the open window with JFileDialog which gives me the opendialog , how do i use the save dialog where the user can type in his text & save the file with a name of his choice

Sushant Prabhu<br />SCJP2<br />SCWCD<br />OCA9i
Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
I won't describe in details. I think you meant JFileChooser when u said JFiledialog. The JFileChooser will simply return the absolute path of the folder and the filename . You will have to do the saving yourself, just like you read the file after you open the open dialog of the JFileChooser and get the name of the file.
JFileChooser filechooser=new JFileChooser();
if( ImagerGlobal.ImageFileChooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION)
String absolutefilename= filechooser.getSelectedFile().getAbsolutePath());
File file=new File(absolutefilename);
FileInputStream fis=new FileInputStream(file);
//now save the data into this file input stream
//and then close the file input stream
hope this helps

Author of JPhotoBrush Pro (
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Have you looked at the tutorial from Sun. Here is a line directly from it. You can get there by clicking the how to use link in the API.
int returnVal = fc.showSaveDialog(FileChooserDemo.this);
I agree. Here's the link:
subject: In JFileDialog how to use the save window
It's not a secret anymore!