This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am uploading a file in servlets. Now..I just need the filename from the filepath which I am uploading. I mean...is there any way to get just the filename (or say the last set of characters) from the filepath. I need to use this filename elsewhere...I cant hardcode it.
I think what you can do to get the filename out of filepath is, treat filepath as string and get the index of last occurence of "/" in the filepath and substring the filename from that index value till the end of the filepath.
String filepath = "c:/documents and setting/desktop/cdss/file1.txt"
Here in this case filename is file1.txt. To get this what we can do is
int idx = filepath.lastIndexOf("/"); String filename = filepath.substring(idx+1);
This will give "file1.txt" in filename.
Hope this helps.
Anna [ March 03, 2005: Message edited by: anna pillutla ]