aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JfileChooser file selection.........? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JfileChooser file selection.........?" Watch "JfileChooser file selection.........?" New topic
Author

JfileChooser file selection.........?

prabhu pandurangan
Ranch Hand

Joined: May 23, 2008
Posts: 120

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.

Looking forward for reply.

Regards,
Prabhu.

Jim Jacob
Greenhorn

Joined: May 27, 2008
Posts: 8
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('.'))


[SCJP,SCWCD,SCBCD]
prabhu pandurangan
Ranch Hand

Joined: May 23, 2008
Posts: 120

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.

Regards,
Prabhu.

Jim Jacob
Greenhorn

Joined: May 27, 2008
Posts: 8
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?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

"Jim Jacob K",

Please check your private messages regarding an important announcement.

Thank you,

Rob


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
prabhu pandurangan
Ranch Hand

Joined: May 23, 2008
Posts: 120
Hi ROB,
I did not receive any private message.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

I don't remember asking YOU to check your private messages
My request was directed at Jim Jacob.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JfileChooser file selection.........?