欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

下載網(wǎng)站圖片代碼并且解析亂碼

 更新時間:2014年05月15日 15:09:11   作者:  
這篇文章主要介紹了下載網(wǎng)站圖片代碼并且解析亂碼的過程,感興趣的朋友可以參考下
復(fù)制代碼 代碼如下:

// 獲取網(wǎng)站對象
ServletContext context = this.getServletContext();
// 獲取網(wǎng)站資源
String path = context.getRealPath("/imgs/人.jpg");
File file = new File(path);
System.out.println(file);
// 設(shè)置響應(yīng)頭通知瀏覽器數(shù)據(jù)的處理方式
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();

相關(guān)文章

最新評論