[JAVA] ดึงนามสกุลไฟล์ จากไฟล์ที่ถูก Upload เข้ามาผ่าน Multipart file

ดึงนามสกุลไฟล์ จากไฟล์ที่ถูก Upload เข้ามาผ่าน Multipart file โดยสามารถใช้ Code ได้ ดังนี้ครับ

  • เพิ่ม Library Apache Commons IO  ลงในไฟล์ pom.xml  ครับ
  • จากนั้นเรียกใช้ Class FilenameUtils  ที่อยู่ใน Library Apache Commons IO
  • ตัวอย่าง Code ที่ใช้ดึงนามสกุลไฟล์ จากไฟล์ที่ถูก Upload เข้ามาผ่าน Multipart file ครับ
    String extension = FilenameUtils.getExtension(file.getOriginalFilename());
    

 


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts to your email.