How do I choose the download location of a report made in Java?

Asked

Viewed 103 times

0

So, I created an application that generates an ODT file... in the code I am specifying exactly where it should be saved, which is in 'c:/test/sample_report.odt'... I put this name to test... the problem is that the file will always be saved in this folder... I don’t want that, when we are browsing the internet and we download a file and click on it, using Chrome for example it already downloads to the folder 'downloads', with firefox or IE a window appears to choose the location where it will be saved, this is what I want... the problem of the way I did is that the person needs to have the folder 'test' in 'c:'... I do not want this, I want to click to work like any other download made on the net... follows my code: .

   try {
    URL arquivo = getClass().getResource(/reports/term.jasper);
    JasperReport jasperReport = (JasperReport) JRLoader.loadObject(arquivo);

   //Aqui é gerado o DTO que será enviado para o IReport
    ArrayList<MinutoTRDto> dataList = getDataBeanList(licitacao);
    JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataList);

    Map<String, Object> parameters = getParametros();            
    JasperPrint print = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);

    JROdtExporter exporterOdt = new JROdtExporter();
    exporterOdt.setExporterInput(new SimpleExporterInput(print));





    // AQUI ESTA O GRANDE PROBLEMA!
    exporterOdt.setExporterOutput(new SimpleOutputStreamExporterOutput("C://teste//sample_report.odt"));
    exporterOdt.exportReport();

} catch (JRException jre) {
    jre.printStackTrace();
}

1 answer

0

If you want the user to choose the location that will save, just use Jfilechooser, then he chooses where he wants to save and you pass the path where will be saved...

  • But Jfilechooser will not work for this case... the report is generated automatically, I click on the button and Gero the report and it already has to be downloaded... I just don’t want to oblige the person to have in unit C: a folder called test... the problem is on this line... --> --> exporterOdt.setExporterOutput(new Simpleoutputstreamexporteroutput("C://test//sample_report.odt");... this "C://test//sample..." creates the file in this folder... there are other reports being saved in the application that Web, only using another library, in this case I am generating ODT...

  • The way we are using in the PDF application (which is also generated automatically) when clicking the report button the file is generated and already saved in the download folder, and if I keep clicking the same button will generate several files ... type "report.pdf", report(1). pdf, report(2).pdf... and so on to the last.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.