title: Download File in Java Spring rest api
body: <p>I want to download a file and for that I have written this code:</p>
  
  <pre><code>public void downoadResume(@PathVariable("id") int id, HttpServletResponse response) {
  try {
      Applicant applicant = applicantService.getOne(id);
      File file = new File(DocumentConstants.DOCUMENTS_PATH + "/" + applicant.getOriginalDocPath());
      // get your file as InputStream
      InputStreamReader is = new InputStreamReader(new FileInputStream(file.getAbsolutePath()));
      // copy it to response's OutputStream
      org.apache.commons.io.IOUtils.copy(is, response.getOutputStream());
      is.close();
      response.flushBuffer();
  } catch (IOException ex) {
      ex.printStackTrace();
  } catch (ResourceNotFoundException e) {
      e.printStackTrace();
  }
  
  }
  </code></pre>
  
  <p>But I am getting this kind of response instead of file, please check:</p>
  
  <pre><code>PK!�?�*��[Content_Types].xml �(���Oo�@��H|k���i�8=��X*���8Y���3i�o��I�RLHs���罟��3��g��G�hc��e5?
  �Z|�ߕE?��Q.��P\�޿��7    ��ꀵX�OR�^?WX�?O���"��K����� �&amp;�R�@��VC̦��QkG��3��%��P7�[�Z���Պ�T&gt;�ʥ�9T\�݃+���1�thO�n�����dk�xP���g���&amp;���g��pƦ���V-���3���O��a�?ġ�H���NZ�?c�˓qz�V2Y�3b��k����'��F/}(�i�ߞ`�{��wK�ۦ�]?����Z��w"���߿�r��p�&lt;����g�x!&gt;
  ��H!�9�}/=
  ���a�&lt;����#:����� ^ ���gQ'sȒGe7�x���x���h�K��G̻ޑ���9C���o٭��/��PK!���N_rels/.rels �(����JA���a�}7�
  "���H�w"����w̤ھ�� �P�^����O֛���;�&lt;�aYՠ؛`G�kxm��PY�[��g
  Gΰino�/&lt;���&lt;�1��ⳆA$&gt;"f3��\�ȾT�?I    S?���������W����Y
  ig�@��X6_�]7~
  f��ˉ�ao�.b*lI�r?j)�,l0�%?�b�
  6�i���D�_���,   �   ���|u�Z^t٢yǯ;!Y,}{�C��/h&gt;��PK!����g�word/_rels/document.xml.rels �(����N�0��H�C�;�:`�n@�����N[��U�{{¦u۲K/��G����?���:��*4)K���H�+S��-{��c�#arQ�?�������b�� ��+��E&gt;�q)+���?,AcƟ(�Z?m�!?E|8����`ӽ��&lt;O�?��~�j|���Q�J�#ʥCGJp0�A�W�2a��m��s2~��OG����C��}�W������    a�z֯�n��H��?KG�?���e�cު�"�I�f�'�7,^?�����1r�'�;��*!���Fϔ�}�n,�?���?ܜ`Е��PQ,Q�?K���x߀��)�WT&gt;)�:�88
  5���;&lt;oY
  </code></pre>
  
  <p>Can you please tell me what wrong I have done in this code?</p>