0

All,

In my project, I have different attachment types like image, audio file, Video file and PDF. I want to sort them based on the extension like .mp4 is video, .pdf is documented like that, How can we write in Java,

One method we can follow gets the extension and compare with extensions required, Is there any better way to do it.

4
  • 1
    URLs don't necessarily have an extension that indicates the content. The only way to know what the content is is through the Content-Type: header. Commented Mar 5, 2019 at 11:53
  • not too much related but this will help you to get file extension commons.apache.org/proper/commons-io/javadocs/api-2.5/org/… Commented Mar 5, 2019 at 11:57
  • Use Apache commons-io stackoverflow.com/questions/605696/get-file-name-from-url Commented Mar 5, 2019 at 11:57
  • I don’t understand what you’re sorting. List<Path>? List<File>? List<URL>? Something other than a List? I’m also not clear on what you’re asking. Are you asking if there’s a better way to determine file type than just examining the extension? Commented Mar 5, 2019 at 13:56

1 Answer 1

0

You can use a mime database. nginx for example uses this one by default.

But this is not always enough. For example, mp4 mime type is video/mp4 but mp4 COULD be an audio file. and you can know for sure without downloading it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.