Home arrow static arrow Java Programming [Archive] - File Chooser
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - File Chooser
This topic has 3 replies on 1 page.

Registered: 6/1/04
File Chooser  
Aug 3, 2004 5:46 AM

I am working on saving a file through the file chooser.

When the user clicks on the save button, it will bring up a save file chooser dialog.

How do you append .txt to the file name while the file chooser window is opened?


Registered: 11/8/00
Re: File Chooser  
Aug 3, 2004 6:01 AM (reply 1 of 3)

Look into using the setFileFilter() method, i'm not sure if it works on a save.

Registered: 6/1/04
Re: File Chooser  
Aug 3, 2004 6:04 AM (reply 2 of 3)

I don't know if that will work. Thanks anyways for looking.

I decided to try another method. Although it is not what I would like, it works to its purpose.

String sPath = file.getPath();            boolean bExtension = sPath.endsWith(".txt");            if (bExtension == false){              sPath += ".txt";} 

Registered: 9/26/01
Re: File Chooser  
Aug 3, 2004 6:26 AM (reply 3 of 3)

What if the user actually WANTS to save it to a particular file name and extension, like "something.dat" - now you've circumvented that. Or, what if there already is a file named "something.dat.txt" and the user specifically didn't want that file to be overwritten - now you've messed that up too. Or, what if they type "something.TXT" or "something.Txt" - your logic will not detect that they typed the desired extension. I wouldn't mess with what they typed - save it with the name they specified.
This topic has 3 replies on 1 page.