zoukankan      html  css  js  c++  java
  • 简单的上传文件和下载文件

    //简单的上传文件和下载文件:
    
    request.setCharacterEncoding("utf-8"); / *设置编码格式 */
    response.setContentType("application/msword");  /*使浏览器能区分数据的种类,这里是word文件类型*/
    Part part = request.getPart("files"); /*取的需要上传的文件*/
    
    
    String path = this.getServletContext().getRealPath("/download/副本.jpg"); /*取的要下载文件的地址*/
    String filename = path.substring(path.lastIndexOf("\")+1); /*取的文件名*/
    response.setHeader("content-disposition","attachment;filename=" + URLEncoder.encode(filename,"utf-8")); 
    int len = 0;
    byte[] bfft = new byte[1024];
    InputStream input = new FileInputStream(path);
     
    OutputStream output = response.getOutputStream();
     
    while((len = input.read(bfft))>0) {
    output.write(bfft, 0, len);
    }
  • 相关阅读:
    vue父子组件传值的方式
    定时任务写法
    仅仅为笔记
    consul剔除某个服务
    mybatis批量查询
    一次eureka的事故
    feign的工作原理
    JVM优化
    threadlocal应用
    秋招总结
  • 原文地址:https://www.cnblogs.com/sjyzz/p/6536688.html
Copyright © 2011-2022 走看看