This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to get filename from fullpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to get filename from fullpath" Watch "how to get filename from fullpath" New topic
Author

how to get filename from fullpath

indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
Hi, how to get the filename, when I have fullpath ..


thanks,
indu
shan raj
Ranch Hand

Joined: Dec 16, 2008
Posts: 42

You can construct the java.lang.File object and call the method getName() to get the file name.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44042
    
  33
Use the path separator, which you can find from the System#getProperties() and System#getProperty(java.lang.String) methods, and you may find more detail of in the File class. Use that as a delimiter to split the path String. This File method might also help; I am not sure.
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
ok thank you, i got this with "//" seperator. Thanks for considering....
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44042
    
  33
How did you get it to work with "//"?
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123


please let me know, if this code is wrong ....
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

Yes, it's wrong. It will only work on systems where file path entries are separated by backslashes. And the version with slashes instead, will only work on systems where file path entries are separated by slashes. So, both are unreliable. However...
shan raj wrote:You can construct the java.lang.File object and call the method getName() to get the file name.

This is the right way to do it.
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
thank you ...
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: how to get filename from fullpath
 
It's not a secret anymore!