Hey, my code fragment is now this:

File fileName = "E:\\Major Project\\FinalLap\\278d.gz.txt.txt";
int index = fileName.toString().lastIndexOf("\\");
filed = fileName.toString().substring(0, index);

And I hope to just get the file's name "278d.gz.txt.txt" after the last instance of "\\" and assign it to variable "filed".
Can anyone tell me what am I doing wrong? Cause I'm still getting the full path.

Thanks a lot!

Recommended Answers

All 2 Replies

check out the params for substring - you select a substring starting at 0 ending at the last \, but you want one starting at the last \ and extending to the end of the string.

filed = fileName.toString().substring(index+1);

got it! thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.