views:

27

answers:

1

I'm having the following problem with a JFileChooser: I create a save dialog and then when I'm trying to save a file, I'm entering a file name into the field and click "Save". Suppose that the directory, which I try to save my file to, contains a subdirectory, which is named exactly like the entered name. In this case JFileChooser opens it instead of saving my file, and I don't know how to make it save a file instead of opening the directory with the same name.

I tried to do something with the file filters, with approveSelection() and changed UI from Windows to default - nothing helps. How to make JFileChooser stop opening a folder and save the file? Is there some way to modify the behavior of the button or am I just doing something wrong?

Update: To be clear: I'm not trying to save a file with the same name, I'm just trying to make JFileChooser get the path so I could append an extension to it. However, I checked Word and Photoshop, neither of them is able to do what I request, so I guess I wish to make everything too perfect. But if there's a way to do what I want, I'll still be glad to hear the solution.

+1  A: 

Neither Windows nor Linux allow file names and directory names to be the same in the same directory as far as I know. Under Linux of course they can be the same with different case lettering :)

Arnold Spence
I'm not trying to save a file with the same name, I'm just trying to get the path so I could append file extension to it. JFileChooser apparently doesn't know that, and that's my problem: he thinks I'm gonna save file exactly with the same name I entered and opens a folder instead. If there's any other way to automatically append a file extension, that would do.
Malcolm