aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 36478
    
  16
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: 36478
    
  16
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
Bartender

Joined: Oct 14, 2005
Posts: 18118
    
    8

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 ...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to get filename from fullpath
 
Similar Threads
About Opening a file
Fully Qualified Path Names (help!)
renameTo()?
calling a Javascript variable in anchor tag
Bad file download problem