웹 개발

[java] 파일 확장자 구하기

노루아부지 2020. 1. 30. 10:54

Apache Commons IO의 FilenameUtils.getExtension을 사용하면 손쉽게 확장자를 구할 수 있습니다.

 

1. Maven dependency

<dependency>
  <groupId>commons-io</groupId>
  <artifactId>commons-io</artifactId>
  <version>2.6</version>
</dependency>

 

 

2. 코드 예제

String ext1 = FilenameUtils.getExtension("/path/to/file/notepad.txt"); // returns "txt"
String ext2 = FilenameUtils.getExtension("excel.exe"); // returns "exe"

 

728x90

'웹 개발' 카테고리의 다른 글

Convert a Map to a POJO  (0) 2020.02.26
JAVA 한글 깨질 경우 인코딩 확인하기  (0) 2020.01.31
파일 업로드 취약점 (webshell upload)  (0) 2020.01.30
[java] https connection  (0) 2019.12.30
java file transfer  (0) 2019.12.27
loading