java - How to save the text file in a path given by JFileChooser? -


i need save text file created in particular path given jfilechooser. save is:

public void actionperformed(actionevent e) {    jfilechooser chooser = new jfilechooser();    int status = chooser.showsavedialog(null);    if (status == jfilechooser.approve_option) {       system.out.print(chooser.getcurrentdirectory());       // don't know how    } 

how save text file in path given jfilechooser?

you want add following after if statement:

file file = chooser.getselectedfile(); filewriter fw = new filewriter(file); fw.write(foo); 

where foo content.

edit:

as want write text file, i'd recommend following:

printwriter out = new printwriter(file); bufferedreader in = new bufferedreader(new filereader(original)); while (true) {     string line = in.nextline();     if (line == null)         break;     out.println(line); } out.close(); 

where original file containing data want write.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -