0

I want to download a CSV file which at server on the location Temp\hello.csv using java code

  1. I have the data. I am populating that data into a CSV file, hello.csv
  2. This file I am saving/storing in server under \Temp folder
  3. The CSV file gets stored at location Temp\hello.csv folder in server.
  4. I want to download this file but I don't know how to do it using java code

1 Answers1

0

This should work (from https://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-async-output-stream):

@RequestMapping("/download")
public StreamingResponseBody handle() {
    return new StreamingResponseBody() {
        @Override
        public void writeTo(OutputStream outputStream) throws IOException {
            File file=new File("Temp\hello.csv");
            FileInputStream stream =new FileInputStream(file);
            IOUtils.copy(stream, outputStream);
        }
    };
}

But there are many other capabilities. (Spring boot service to download a file , Downloading a file from spring controllers , ...)

Community
  • 1
  • 1
benkuly
  • 1,144
  • 10
  • 28