• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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: 21775
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator

Hi ROB,
I did not receive any private message.

 
Rob Spoor
Sheriff
Posts: 21775
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't remember asking YOU to check your private messages
My request was directed at Jim Jacob.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!