天天看點

Hutools工具類和IOUtils工具類

/**
	 * <功能描述>
	 * @Description: 下載下傳控件
	 * @author: GdlSky
	 * @Date: 2020/12/22 0022
	 * @Param: response
	 * @return: Void
	 */
	@RequestMapping(value = "/downloadControl", method = RequestMethod.GET)
	public void getTest(HttpServletResponse response){
		try {
			InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("control.zip");
			byte[] fileByte = IOUtils.toByteArray(inputStream);
			response.setContentType("application/octet-stream");
			//如果輸出的是中文名的檔案,在此處就要用URLEncoder.encode方法進行處理
			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("用戶端安裝包.zip", "UTF-8"));
			// 寫出
			ServletOutputStream outputStream = response.getOutputStream();
			IOUtils.write(fileByte, outputStream);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
           

以上就是處理包裡面的一個附件,進行下載下傳,其實沒什麼,但是主要展現了IOUtils這個工具類的好處,簡潔,友善。

import org.apache.commons.io.IOUtils; 來自于apach;

另外:有時間 再進行補充

Hutools工具類介紹(java )