package com.fgkj.controller; import com.fgkj.util.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.io.*; import javax.annotation.Resource; @RequestMapping("fileDownload") @RestController @Api(tags = "fileDownload接口") public class FileDownloadController{ /*private String PageName; private String filename; private String arr_Td; private String arr_Th; private String contentLength;*/ //返回一个输入流,作为一个客户端来说是一个输入流,但对于服务器端是一个 输出流 @PostMapping("downloadFile") @ApiOperation(notes = "TODO ",value="downloadFile") public InputStream getDownloadFile(@RequestParam String filename,@RequestParam String contentLength){ InputStream is = null; filename = "spket-1.6.23.jar"; try { is = new FileInputStream("D:\\spket-1.6.23.jar"); //解解乱码 filename = new String(filename.getBytes("GBK"),"ISO-8859-1"); contentLength = is.available()+""; System.out.println(contentLength); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println("返回输入流"+is); return is; } }