สารบัญ
ชวา ชื่อไฟล์、เส้นทางไฟล์จากนามสกุลไฟล์รับ
ในภาษาจาวาชื่อไฟล์จากนามสกุลไฟล์นี่คือตัวอย่างซอร์สโค้ดสำหรับการดึงข้อมูล
ตัวอย่างโปรแกรม
/**
* ファイル名から拡張子を返します。
* @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(ret2); }
◆ผลลัพธ์
html html
