0

当我在我的应用程序中添加数据时,它会保存在 CSV 文件中。我还有另一种选择来下载相同的 CSV 文件。但它给出了错误。我的代码是:

String csvPath = Utility.getTestCSVFilePath();

        response.setContentType("application/x-download");

        response.setHeader("Content-Disposition", "attachment;filename=\"" +test.getTestName()+".csv"+ "\"");

        PrintWriter responseOut = null;

        try {
            responseOut = response.getWriter();
            InputStream inputStream = new FileInputStream(csvPath);
            OutputStream out = response.getOutputStream();
            IOUtils.copy(inputStream, out);
            out.flush();
            out.close();
            inputStream.close();
        } catch (IOException e) {
            responseOut.write("Some error has occurred while preparing the file for download.");
        }   

当我调试代码时,它在该行中给出错误:

OutputStream out = response.getOutputStream();

什么问题,请帮忙。

4

1 回答 1

0

尝试移动这条线 responseOut = response.getWriter();

inputStream.close();看看它是否有效

于 2013-08-28T05:28:52.950 回答