开发者

How to get the path from a file URL?

开发者 https://www.devze.com 2023-03-31 12:25 出处:网络
I have Strings in this format : file://c:/Users/.... file://E:/Windows/.... file:///f:/temp/.... file:///H:/somethi开发者_如何转开发ng/....

I have Strings in this format :

file://c:/Users/....
file://E:/Windows/....
file:///f:/temp/....
file:///H:/somethi开发者_如何转开发ng/....

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();


you can replace the string "file://" in your string with nothing:

String path = yourString.replace("file://", "");


What about that?

String path = yourString.replaceFirst("file:[/]*", "");
0

精彩评论

暂无评论...
验证码 换一张
取 消