package com.th.demo.tools;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

public class DownLoad extends HttpServlet {


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

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

		try {
			 String downFilename=request.getParameter("curfile");
			 String path ="C:/";
			 String filepath=request.getParameter("path");
				// response.setContentType("text/plain");
				response.setContentType("application/vnd.android.package-archive");
			 response.setHeader("Location",downFilename);
			 response.setHeader("Content-Disposition", "attachment; filename="
			 + "ad.apk");
			OutputStream outputStream = response.getOutputStream();
			InputStream inputStream = new FileInputStream("c:/ad.apk");
			byte[] buffer = new byte[1024];
			int i = -1;
			while ((i = inputStream.read(buffer)) != -1) {
				outputStream.write(buffer, 0, i);
			}
			outputStream.flush();
			outputStream.close();
		} catch (FileNotFoundException e1) {
			System.out.println("û���ҵ���Ҫ���ļ�");
		} catch (Exception e) {
			System.out.println("ϵͳ�����뼰ʱ�����Ա��ϵ");
		}

	}

}
