Avoiding multiple If statements in Java

后端 未结 13 785
北恋
北恋 2020-12-30 07:52

I\'ve coded a method something like this. But I guess this should undergo refactoring. Can any one suggest the best approach to avoid using this multiple if statements?

相关标签:
13条回答
  • 2020-12-30 08:26

    Easiest and shortest way for this particular problem would be using the builtin Java SE or EE methods.

    Either in "plain vanilla" client application (which derives this information from the underlying platform):

    String mimeType = URLConnection.guessContentTypeFromName(filename);
    

    Or in a JSP/Servlet web application (which derives this information from the web.xml files):

    String mimeType = getServletContext().getMimeType(filename);
    
    0 讨论(0)
提交回复
热议问题