servlet实现简单下载(copy)

public class CopyDataServlet extends HttpServlet {

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

		String realRoot = this.getServletConfig().getServletContext().getRealPath(
				"/")+"/data/";
		File theFile = LYFLDAPUtil.readDatFileOfCurDay();
		if(null != theFile){
			String src = theFile.getName();
			SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
			String dateString = sf.format(new Date());
			String dst = realRoot + dateString+".dat";
			System.out.println(theFile.getName());
			InputStream in = new FileInputStream(LYFLDAPUtil.SAMETIME_FILE_PATH + File.separator +src); //source file
			OutputStream out = new FileOutputStream(dst);//destination file

			byte[] buf = new byte[1024];
			int len;
			while ((len = in.read(buf)) > 0) {
			out.write(buf, 0, len);
			}
			in.close();
			out.close();
		}
		
		

	}

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

		doGet(request, response);
	}

}

你可能感兴趣的:(servlet)