• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFileChooser

 
ajathsatru ajathsatru
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use JFileChooser to save a file.. also iam including *.properties in the fileFilter

Suppose if i select the Files of type as *.properties and when i give the filename as test, the file is saved as "test" instead of "test.properties"..

do we have to manually add the extension for the filename...

then what's the use of filefilter in SaveDialog ???

here's is my code
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new MyFileFilter(new String[]{"properties"}, "")); // this string array is the list of extensions
if(chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
{
File file = chooser.getSelectedFile();
out = new ObjectOutputStream(new FileOutputStream(file);
out.writeObject(myobject);
out.close();
}


Also there is a code sample at

http://www.particle.kth.se/~lindsey/JavaCourse/Book/Java/Chapter09/chooser.html
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran into this in Perl too.

The solution was to explicitly append the extension to the file name, otherwise it's only saved with the name the user entered. The purpose of a file filter is to filter out filenames with other extensions from the file chooser dialog, not to automatically append the extension.

Hope that helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!