• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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('.'))
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Jim Jacob K",

Please check your private messages regarding an important announcement.

Thank you,

Rob
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi ROB,
I did not receive any private message.

 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't remember asking YOU to check your private messages
My request was directed at Jim Jacob.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic