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

}


Posted by '김용환'
,