Results 1 to 2 of 2
  1. #1
    fedex646 is offline Member
    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0

    Post IO stream problem

    based on my list size i want the data written on the csv file differently. for that i created 2 methods and placed a if condition in my csv servlet class. Here below I copied entire try catch block. But i am asking for the two methods listes as write csv and create CSvwithout data. writecsv is working good where as create csv is not appending the string empy data whose value i defined as "no data found" to the csv file. Can anyone let me know what cud be the issue

    try {
    String Productlist = req.getParameter("Productlist");
    String DMAlist = req.getParameter("DMAlist");
    String Metriclist = req.getParameter("Metriclist");
    String Distlist = req.getParameter("Distlist");
    String Yearmonthlist = req.getParameter("Yearmonthlist");
    String Tablename = req.getParameter("Tablename");
    response.setContentType("text/csv");
    response.setHeader("Content-Disposition",
    "attachment; filename=data.csv");

    if ((Productlist != null) && (DMAlist != null)
    && (Metriclist != null) && (Distlist != null)
    && (Yearmonthlist != null)) {
    exportToExcelList = domesticServiceImpl.getDomesticDMAHist(
    Productlist, DMAlist, Metriclist, Distlist,
    Yearmonthlist);
    } else {
    exportToExcelList = domesticServiceImpl
    .getCompleteDMAHistList();
    }
    if (exportToExcelList.size() > 0) {
    writeCsv(exportToExcelList, seperator, output);
    } else {
    createCSVWithoutData(EMPTYDATA, output);
    }
    } catch (Exception e) {
    log.error("Exception while downloading offers excel sheet . ", e);
    System.out.println(e);
    e.printStackTrace();
    throw new ServletException(e);
    } finally {
    if (output != null) {
    System.out.println(output);
    output.close();
    // clearing the objects for reclaiming allocated memory
    }
    }
    }

    public void createCSVWithoutData(String EMPTYDATA, OutputStream output)
    throws IOException {

    System.out.println(EMPTYDATA);
    OutputStreamWriter outWriter = new OutputStreamWriter(output);
    BufferedWriter writer = new BufferedWriter(outWriter, (int) MEG);
    writer.append(EMPTYDATA);
    writer.flush();
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

Similar Threads

  1. Help with input stream
    By Slice28 in forum New To Java
    Replies: 1
    Last Post: 03-14-2012, 10:45 PM
  2. Problem with Object Stream
    By er.raj in forum New To Java
    Replies: 6
    Last Post: 03-13-2012, 04:38 PM
  3. IO stream
    By sadeem in forum New To Java
    Replies: 4
    Last Post: 04-10-2011, 09:08 PM
  4. Replies: 3
    Last Post: 09-07-2009, 09:27 AM
  5. stream redirection
    By Ed in forum New To Java
    Replies: 1
    Last Post: 07-02-2007, 05:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •