title: Setting content type in Java for file download
body: <p>In my application I like to provide file download facility. I set the file types to <code>response.setContentType</code>. How can I set the content types for almost all known file types? Is there any easy way? or I need to set it manually like i do now, which is given below.</p>
  <pre><code>if (pictureName.indexOf(&quot;jpg&quot;) &gt; 0) {
     res.setContentType(&quot;image/jpg&quot;);
  } else if (pictureName.indexOf(&quot;gif&quot;) &gt; 0) {
     res.setContentType(&quot;image/gif&quot;);
  } else if (pictureName.indexOf(&quot;pdf&quot;) &gt; 0) {
     res.setContentType(&quot;application/pdf&quot;);
     res.setHeader(&quot;Content-Disposition&quot;, &quot;inline; filename=\&quot;&quot; + pictureName + &quot;\&quot;&quot;);
  } else if (pictureName.indexOf(&quot;html&quot;) &gt; 0) {
     res.setContentType(&quot;text/html&quot;);
  } else if (pictureName.indexOf(&quot;zip&quot;) &gt; 0) {
     res.setContentType(&quot;application/zip&quot;);
     res.setHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=\&quot;&quot; + pictureName + &quot;\&quot;&quot;);
  }
  </code></pre>