I have various urls like this:
String a = "file:./bla/file.txt"; // Valid, see See [RFC 3986][1], path - rootless definition
String b = "file:.file.txt"; // Valid, see See [RFC 3986][1], path - rootless definition
String c = "file:./file.txt"; // Valid, see See [RFC 3986][1], path - rootless definition
String d = "file:///file.txt";
String e = "file:///folder/file.txt";
String f = "http://example.com/file.txt";
String g = "https://example.com/file.txt";
These are all valid URLS, and I can convert them to a URL in java without errors:
URL url = new URL(...);
I want to extract the filename from each of the examples above, so I'm left with just:
file.txt
I have tried the following, but this doesn't work for example b above (which is a valid URL):
b.substring(path.lastIndexOf('/') + 1); // Returns file:.file.txt
I can prob write some custom code to check for slashes, just wondering if there a better more robust way to do it?
./.file.txtI wouldn't expect the file name to befile.txt