Hi Ranchers, While selected a file from FileChooser, file name along with its extension is retrieved, but for me i need only the filename; For example: if my file name is 'name.log' and if i select the file name from the directory, i should get only the file name 'name' alone instead, im getting the file name with its extension as 'name.log' and if i save it, it consider it as a new file name and saves it as 'name.log.log' as a new file and file already exist error is not thrown.
Why dont you do something like this: Get the selected file name with extension using getSelectedFile() from th e FileChooser, then extract the file name without the etension from it, before attempting to save. Something like this: filename.substring(0,filename.lastIndexOf('.'))
Joined: May 23, 2008
Hi Jim, Im using a I/O file 'java.io.File', example
File fileName = chooser.getSelectedFile(); In this case how to extract it, if it is a string we can do as what you said; Looking forward for your reply.
Joined: May 27, 2008
It can still be done, using getName() method of the java.io.File. If you do this, the you will have to re-write the code that saves the file, to use this modified file name.
Instead of doing all these, why dont you remove the code which is adding the ".log" extension to the file being saved?