MENU

Java 파일 이름에서 확장자 얻기

목차

자바 파일 이름파일 경로에서확장자얻기

Java에서파일 이름에서확장자를 얻는 샘플 소스입니다.

샘플 프로그램

/**
 * ファイル名から拡張子を返します。
 * @param fileName ファイル名
 * @return ファイルの拡張子
 */
public static String getSuffix(String fileName) {
    if (fileName == null)
        return null;
    int point = fileName.lastIndexOf(".");
    if (point != -1) {
        return fileName.substring(point + 1);
    }
    return fileName;
}


실행 결과

◆실행예

/** * 예제 실행 * @param args */ public static void main(String[] args) { String ret1 = getSuffix("test.html"); System.out.println(ret1); String ret2 = getSuffix("C:\\test.html"); System.out.println

◆출력 결과

html html

  • URL을(를) 확인했습니다!
목차