当前位置 : 主页 > 编程语言 > java >

jsp--servlet实现文件的下载

来源:互联网 收集:自由互联 发布时间:2021-06-25
package com.lideng.servlet;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;impor
package com.lideng.servlet;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ReaderText extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		InputStream is =new FileInputStream(new File("D:\\Notepad++\\change.log"));//根据自己的实际情况填写路径
		int n=0;
		byte [] b=new byte[1024];
		while((n=is.read(b))!=-1){
			
			response.getWriter().write(new String(b));
		}
		is.close();
			
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}

}
上一篇:服务存储在DB中的JSP
下一篇:jsp(待改)
网友评论