whycrzh
2021-01-28 9f05d9863af714b206bdfffe2096d60a942c9d23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;  
    }
 
}