title: Downloading file from Java servlet gives null
body: <p>I am trying to create a method that allows users to download a file on the file system via a Servlet. Right now, the correct <code>filename</code> shows on the download and a file is downloaded but the contents of the file are always null.</p>
  
  <p>I've also tried to get the file contents to print to the console but nothing is showing up.</p>
  
  <p>Can anyone suggest what I've done wrong here?</p>
  
  <p>Thanks</p>
  
  <pre><code>String filePath = "uploads/" + request.getParameter( "filename" );
  File downloadFile = new File( filePath );
  
  String relativePath = getServletContext().getRealPath( "" );
  System.out.println( "relativePath = " + relativePath );
  
  ServletContext context = getServletContext();
  
  String mimeType = context.getMimeType( filePath );
  if( mimeType == null )
  {
      mimeType = "application/octet-stream";
  }
  System.out.println( "MIME type: " + mimeType );
  
  response.setContentType( mimeType );
  response.setContentLength( (int) downloadFile.length() );
  
  String headerKey = "Content-Disposition";
  String headerValue = String.format( "attachment; filename=\"%s\"", downloadFile.getName() );
  response.setHeader( headerKey, headerValue );
  byte[] bytes = Files.readAllBytes( downloadFile.getAbsoluteFile().toPath() );
  OutputStream outStream = response.getOutputStream();
  
  System.out.println( bytes.toString() );
  
  outStream.write( bytes );
  
  outStream.flush();
  outStream.close();
  </code></pre>
  
  <p><strong>Annotations</strong></p>
  
  <pre><code>@WebServlet(urlPatterns =
  { "/Routing/*" })
  @MultipartConfig(location = "/tmp", fileSizeThreshold = 1024 * 1024,     maxFileSize = 1024 * 1024 * 5, maxRequestSize = 1024 * 1024 * 5 * 5)
  public class Routing extends HttpServlet
  {
  </code></pre>