I have a filepath like filepath = "Y:\abc\hello\doc.txt". I want to get substring from "\doc.txt". How can I do it using Java code.
Asked
Active
Viewed 53 times
0
-
use the split method of the String class, split on \ and keep "\" + last result. – Stultuske May 31 '22 at 09:05
-
Why do you want `\doc.txt` instead of `doc.text`? – Mark Rotteveel May 31 '22 at 09:17
-
Have a look at [`Path#getFileName()`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Path.html#getFileName()) – QBrute May 31 '22 at 09:43