title: How to make it as downloadable excel file using servlets
body: <p>I am reading a txt file and writing it into excel file, but while making it as downloadable excel file it is not writing any data to excel and giving showing this message
  <img src="https://i.stack.imgur.com/SB85y.jpg" alt="Warning message while opening the xls file"></p>
  
  <p>logic for downloading into excel</p>
  
  <pre><code>response.setContentType("application/vnd.ms-excel");
      response.setHeader("Content-Disposition", "attachment; filename=sampleName.xls");
      String path = getServletContext().getRealPath(file);
      File file = new File(path);
      System.out.println("File:" + file);
      FileInputStream is = new FileInputStream(uploadFilePath
              + File.separator + file.getName());
      try {
          InputStreamReader isr = new InputStreamReader(is);
          BufferedReader br = new BufferedReader(isr);
          ArrayList&lt;ArrayList&lt;String&gt;&gt; exceldata = new ArrayList&lt;ArrayList&lt;String&gt;&gt;();
          ArrayList&lt;String&gt; headerRow = new ArrayList&lt;String&gt;();
          headerRow.add("Date and Time");
          headerRow.add("NMEA Message Type");
          headerRow.add("Fragments in the message");
          headerRow.add("Fragments no");
          headerRow.add("AIS MessageType");
          headerRow.add("Repeat Indicator");
          headerRow.add("MMSI Number");
          headerRow.add("AIS Version");
          headerRow.add("IMO Number");
          headerRow.add("Navigational status");
          headerRow.add("Rate Of Turn(ROT)");
          headerRow.add("Speed Over Ground(SOG)");
          headerRow.add("Position Accuracy(PA)");
          headerRow.add("Longitude");
          headerRow.add("Latitude");
          headerRow.add("Course Over Ground(COG)");
          headerRow.add("Heading(HDG)");
          headerRow.add("Time Stamp");
          exceldata.add(headerRow);
          String strLine;
          while ((strLine = br.readLine()) != null) {
              System.out.println(strLine);
              exceldata.add(decodeAisData(strLine));
          }
          writeDataToExcelFile("praveen",exceldata);
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } finally {
          try {
              is.close();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>For writing the data to excel:</p>
  
  <pre><code>private void writeDataToExcelFile(String string, ArrayList&lt;ArrayList&lt;String&gt;&gt; excelData) {
      HSSFWorkbook myWorkBook = new HSSFWorkbook();
      String sheetName = "";
      sheetName = "Document-" + 0;
      HSSFSheet mySheet = myWorkBook.createSheet(sheetName);                  
      HSSFRow myRow = null;
      HSSFCell myCell = null;
      for (int rowNum = 0; rowNum &lt; excelData.size(); rowNum++) {
          ArrayList&lt;String&gt; rowData = excelData.get(rowNum);
          myRow = mySheet.createRow(rowNum);
          for (int cellNum = 0; cellNum &lt; rowData.size(); cellNum++) {
              myCell = myRow.createCell(cellNum);
              myCell.setCellValue(rowData.get(cellNum));
          }
      }
      try {
          FileOutputStream out = new FileOutputStream("my.xls");
          myWorkBook.write(out);
          out.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>So please give solution to make as it as downloadable.Thanks</p>