apache commons io의 FilenameUtils 클래스 사용 예제
import static org.junit.Assert.assertTrue;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
@Test
public void test()
String url="http://host.google.com/abc/def/ghi/img.jpg?height=500&width=500";
String path = StringUtils.substringBefore(url, "?");
assertTrue("jpg".matches(FilenameUtils.getExtension(path)));
assertTrue("img".matches(FilenameUtils.getBaseName(path)));
assertTrue("http://host.google.com/abc/def/ghi/".matches(FilenameUtils.getFullPath(path)));
assertTrue("http://host.google.com/abc/def/ghi".matches(FilenameUtils.getFullPathNoEndSeparator(path)));
assertTrue("http://host.google.com/abc/def/ghi/".matches(FilenameUtils.getPath(path)));
}
'general java' 카테고리의 다른 글
[spring boot 1.3.5] redis cluster 적용 (0) | 2016.06.21 |
---|---|
play1 framework 유틸리티 살펴보기 - play help (0) | 2016.06.13 |
[play1] 버전 업하기 1.3.0 -> 1.3.4 (또는 1.4.2) (0) | 2016.05.26 |
[guava] symmetric difference/difference, relative(absolute) complement 개념 (0) | 2016.04.28 |
[jenkins] 간단한 인증 처리 설정하기 (0) | 2016.04.18 |