下載網站圖片代碼并且解析亂碼
更新時間:2014年05月15日 15:09:11 作者:
這篇文章主要介紹了下載網站圖片代碼并且解析亂碼的過程,感興趣的朋友可以參考下
復制代碼 代碼如下:
// 獲取網站對象
ServletContext context = this.getServletContext();
// 獲取網站資源
String path = context.getRealPath("/imgs/人.jpg");
File file = new File(path);
System.out.println(file);
// 設置響應頭通知瀏覽器數據的處理方式
response.setHeader("content-disposition",
"attachment;filename="+
URLEncoder.encode(file.getName(),"utf-8")); // 處理文件名亂碼 指定圖片格式為下載
// 指定字節(jié)輸入流對象
FileInputStream in = new FileInputStream(file);
// 獲取字節(jié)輸出流對象
ServletOutputStream out = response.getOutputStream();
// 邊讀邊寫
byte [] b = new byte[1024];
int len = 0;
while((len = in.read(b)) != -1){
out.write(b, 0, len);
}
// 釋放資源
in.close();
相關文章
jsp中將后臺傳遞過來的json格式的list數據綁定到下拉菜單select
后臺傳遞過來的json格式的list數據如何綁定到下拉菜單,下面有個不錯的示例,感興趣的朋友可以參考下2013-10-10

