I have Strings in this format :
file://c:/Users/....
file://E:/Windows/....
file:///f:/temp/....
file:///H:/something/....
How can I get just c:/Users/...
or H:/something/...
?
Tested and will replace an arbitrary number of slashes.
String path = yourString.replaceFirst("file:/*", "");
And if you only want it to match two or three slashes
String path = yourString.replaceFirst("file:/{2,3}", "");
String path = new java.net.URI(fileUrl).getPath();
您可以将字符串中的字符串“ file://”替换为空:
String path = yourString.replace("file://", "");
那个怎么样?
String path = yourString.replaceFirst("file:[/]*", "");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.