zoukankan      html  css  js  c++  java
  • springMvc文件下载

    //主要看导入的是那些类

    import com.ibm.db.service.ITopicService;
    import org.apache.commons.io.FileUtils;
    import org.springframework.http.HttpHeaders;
    import org.springframework.http.HttpStatus;
    import org.springframework.http.MediaType;
    import org.springframework.http.ResponseEntity;

    @RequestMapping("/down")
    public ResponseEntity<String> download() throws IOException {
    String path="D:\upload\file\20160419211657.txt";//需要下载的文件
    File file=new File(path);
    HttpHeaders headers = new HttpHeaders();
    String fileName=new String("你好.txt".getBytes("UTF-8"),"iso-8859-1");//为了解决中文名称乱码问题
    headers.setContentDispositionFormData("attachment", fileName);
    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    /* String sendString=new String( bytes , "ISO-8859-1" );*/
    return new ResponseEntity<String>(new String(FileUtils.readFileToByteArray(file),"ISO-8859-1"),
    headers, HttpStatus.CREATED);
    }

  • 相关阅读:
    java导出pdf格式文档
    本地文件夹选择框
    将文件解除占用
    Windows 进入上帝模式窗口
    Windows 10 系统获取密钥方法
    CentOS7 systemctl 命令
    一键立即息屏
    定时关闭程序
    CentOS 7 FTP的安装与配置
    SQL基础
  • 原文地址:https://www.cnblogs.com/zml-java/p/5418978.html
Copyright © 2011-2022 走看看