程序员分类

程序员

  • 前端:html、css、javascript、bootstrap、jQuery、Node.js、Augular、TypeScript、ReactJS、vue.js
  • 后端:Java、Python、Go、C/C++、Ruby、Node.js、PHP、kotlin
  • 移动端:Anodroid、ios、react native、kotlin
  • 大数据:Hadoop、Spark、Flink
  • 运维:Unix/Linux、Mysql、Python
  • 测试:功能测试,性能测试
  • 云计算:AWS、阿里云,各种云
  • 全栈:前端+后端
  • 人工智能:机器学习、深度学习、自然语言处理
    package com.adair.servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;

public class FileServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String realPath = “C:\Users\Adair\Desktop\庆林.png”;
String fileName = realPath.substring(realPath.lastIndexOf(“\”) + 1);//得到文件名
System.out.println(“文件的路径”+realPath);
//设置浏览器能够支持我们下载的东西
resp.setHeader(“Content-disposition”,“attachment;filename=”+URLEncoder.encode(fileName,“UTF-8”));
FileInputStream fis = new FileInputStream(realPath);
ServletOutputStream os = resp.getOutputStream();
int len=0;
byte[] buffer = new byte[1024];
while ((len=fis.read(buffer))!=-1){
os.write(buffer,0,len);
}
fis.close();
os.close();

}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    super.doPost(req, resp);
}

}

你可能感兴趣的:(java,java)