javaweb,文件下载设置

FileInputStream is = new FileInputStream(new File("C:\\Users\\ys\\Desktop\\内蒙\\kedacom相关操作手册\\pmchelp.pdf"));
		// resp.setContentType("application/octet-stream"); 
		resp.setContentType("application/pdf"); 
		//resp.setHeader("Content-Disposition", "attachment;fileName="+"20170315160623.pdf"); 
		ServletOutputStream sos = resp.getOutputStream();
		byte[] bytes = new byte[1024];int count = 0;
		while ((count = is.read(bytes)) != -1) { 
			sos.write(bytes, 0, count); 
		} 
		is.close();sos.close();

你可能感兴趣的:(java)