• Post Reply Bookmark Topic Watch Topic
  • New Topic

I have some problem using the JFileChooserDialog.

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
below is my code:
JFileChooserDialog fc = new JFileChooserDialog();
int rVal = fc.showSaveDialog();
if (rVal == JFileChooserDialog.APPROVE_OPTION) {
// I want to get the file name the user texted
.......

//then I can create a new file with the name user offered.
//I have done this.
}
 
Stefan Willi
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your problem?

to get the selected file?

Here a sample for opening only a directory.


stefan
[ March 17, 2005: Message edited by: Stefan Willi ]
 
sasi kala
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

This code will shows save dialog box and reads file name from user. If user didn't specify a name do nothing.



All The Best
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is I can't creat a new file when I pressed the "Save" button.I've google so much about how to use JFileChooser,but not found how to creat a new file when saved.Maybe someone can give me an example,when pressed the button,then I can see a new file in my computer.
Thank you.
 
Stefan Willi
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use file.createNewFile(), this returns a boolean, which indecate you, if the creation of the file was sucessfully.


stefan
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah!I do be confused by the java I/O.
Now the problem is solved.I want learn more about java I/O.Would you mind adviseing me some materails to learn? I would not ask so stupid question next time.
But who knows.
I have to work harder.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!