开发者

How to get the path from a file URL?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜