Hi,
i'm trying to create a "Save as" frame with my small program.
It must open a Save As windows where i could choose the name of the file (txt) that i want to save.

Is there any method to do this?
i didn't find with google.
Thanx

You can use JFileChooser

JFileChooser fc = new JFileChooser();
      fc.showSaveDialog(null);
      File outFile = fc.getSelectedFile();
      System.out.println(outFile.getName());

There are many other options in JFiuleChooser - see the API doc.

Edited 5 Years Ago by JamesCherrill: n/a

Thank you James,

i will close this thread and comeback with another thread because my problem is more complex.
in fact i coded a GUI with Two buttons and two TextArea:

the first button is used to select txt files in a directory// this is working well.
after i 've selected files , they are displayed in th etex are// this is working too.

the second button is used to save the content of all txt files selected before in one file//
in fact this button must open a Save As window.

Let me come back to you this evening i will put my piece of code.
it's an earlier code that i modified, maybe you remember.

My code is working very well in console mode and now i'm trying to build a gui with my pgm.

Thank you

The solution is :

import java.io.File;

import javax.swing.JFileChooser;

public class JFChooser

{
  public static void main(String[] argv) throws Exception{
    JFileChooser chooser = new JFileChooser();
    //File f = new File(new File("filename.txt").getCanonicalPath());
    chooser.setSelectedFile(new File("c:/Temp2/anyFilename.txt") );
    chooser.showSaveDialog(null);
    File curFile = chooser.getSelectedFile();
  }
}
This article has been dead for over six months. Start a new discussion instead.