title: how to set res.setContentType("application/xls") dynamic in spring while downloading the file
body: <p>I want to download a file which is available in the server itself</p>
  
  <p><code>AppName\resources\attachemnts\file.extension(this can be anything)</code> i have got the code from the net the following is the same.</p>
  
  <pre><code>@RequestMapping(value = "/fileDownload", method = RequestMethod.GET)
          public void handleFileDownload(@RequestParam("fileLocation") String fileLocation,HttpServletResponse res) {
              try {
  
                  URL url = getClass().getResource(fileLocation);
                  File f = new File(url.toURI());
                  System.out.println("Loading file "+fileLocation+"("+f.getAbsolutePath()+")");
                  if (f.exists()) {
                      res.setContentType("application/xls");
                      res.setContentLength(new Long(f.length()).intValue());
                      res.setHeader("Content-Disposition", "attachment; filename=Test.xls");
                      FileCopyUtils.copy(new FileInputStream(f), res.getOutputStream());
                  } else {
                      System.out.println("File"+fileLocation+"("+f.getAbsolutePath()+") does not exist");
                  }
              } catch (Exception e) {
                  System.out.println(e.getMessage());
              }
          }
  </code></pre>
  
  <p>i have to set <code>res.setContentType("application/xls");</code> dynamic since the file type is going to be different each time.</p>
  
  <p>How to get file type?</p>