나는이 형식 문자열이 있습니다파일 URL에서 경로를 가져 오는 방법은 무엇입니까?
이file://c:/Users/....
file://E:/Windows/....
file:///f:/temp/....
file:///H:/something/....
가 어떻게 그냥 c:/Users/...
또는 H:/something/...
받을 수 있나요?
나는이 형식 문자열이 있습니다파일 URL에서 경로를 가져 오는 방법은 무엇입니까?
이file://c:/Users/....
file://E:/Windows/....
file:///f:/temp/....
file:///H:/something/....
가 어떻게 그냥 c:/Users/...
또는 H:/something/...
받을 수 있나요?
테스트되었고 임의의 수의 슬래시가 대체됩니다.
String path = yourString.replaceFirst("file:/*", "");
그리고 당신은 단지 그것을 두 개 또는 세 개의 슬래시
String path = yourString.replaceFirst("file:/{2,3}", "");
당신이 문자열 "파일 : //"대체 할 수있는 문자열에 아무것도 : 그것에 대해
String path = yourString.replace("file://", "");
그리고 그것은 무엇'파일을 추천 슬래시가 포함 된 경우 일치 할 경우 : ///'를? –
위의 대답은 file : /// f :/temp/.... file : /// H :/something/....을 만족하지 않습니다. – developer
'String path = yourString.replaceFirst ("^ file : // /? "," ");'- String.replace (String, String)'메소드가 없습니다. –
무엇을?
String path = yourString.replaceFirst("file:[/]*", "");
'[]'는 중복됩니다. –
String path = new java.net.URI(fileUrl).getPath();
두 번째 해결 방법은 매우 –
+1입니다. :) – user802421
'[]'는 중복됩니다. 또한'///?'는'/ {2,3}'보다 짧고 간단합니다. –