導航:首頁 > 編程語言 > java下載文件設置頭

java下載文件設置頭

發布時間:2024-12-07 06:13:34

『壹』 java 下載文件設置文件名

怎麼的下載方式、方法。

你在後台設置一個,

<%
response.setContentType(fileminitype);
response.setHeader("Location",filename);
response.setHeader("Cache-Control", "max-age=" + cacheTime);
response.setHeader("Content-Disposition", "attachment; filename=" + filename); //filename應該是編碼後的(utf-8)
response.setContentLength(filelength);
OutputStream outputStream = response.getOutputStream();
InputStream inputStream = new FileInputStream(filepath);
byte[] buffer = new byte[1024];
int i = -1;
while ((i = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, i);
}
outputStream.flush();
outputStream.close();
inputStream.close();
outputStream = null;
%>

『貳』 java 如何下載文件

httpURLConnection conn;
conn.getInputStream;
再將這個stream 寫到文件就可以了

『叄』 java如何實現超鏈接下載

可以使用設置response header的方式來進行下載,讓後redirect到其他頁面。版
http://hi..com/%B3%A4%D3%C2%5Fzone/blog/item/047ffb5c566fe44bfbf2c0d1.html
這個權是asp的,修改下即可。

『肆』 Java:關於保存文件的路徑問題,如何通過response設置

1、首先我們客戶端下載文件,是從伺服器上面下載的。是不允許我們操作客戶端的文件的以下是設置伺服器端的文件路徑。

response.reset();
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition","attachment;filename=InspectionExcel.xlsx");//設定輸出文件頭
response.setHeader("Set-Cookie","fileDownload=true;path=/");
response.setContentType("application/msexcel");
OutputStreamos=null;
try{
DownFileopenFile=newDownFile();
StringfileExcel=openFile.fileLookForWord(request,response);//伺服器目錄
os=newFileOutputStream(fileExcelPath);
incomingQualityManageService.exportInspectionExcel(itemCode,cateGory,cateName,supplierMan,poNum,
receiveNum,porject,beginDate,endDate,null,"N",os);
}finally{
if(os!=null){
os.close();
}
}

2、實在要控制的話,可以用applet技術,但是有比較大的局限性。需要的話可以私聊我。

『伍』 Javaweb中的文件下載實現

需要在響復應頭部加上一制些標示,告訴瀏覽器這個是文件下載。

如果你用了框架比如struts,需要加如下配置
<result name="success" type="stream">
<param name="contentType">application/octet-stream;charset=ISO8859-1</param>
<param name="inputName">fileStream</param>
<param name="contentDisposition">attachment;filename="${fileName}"</param>
<param name="bufferSize">2048</param>
</result>
如果沒有用框架,就手動在返回對象添加這些contentType

閱讀全文

與java下載文件設置頭相關的資料

熱點內容
捕魚達人歷史版本 瀏覽:73
mp4視頻文件解密軟體 瀏覽:62
多軸編程哪個軟體最方便 瀏覽:27
老平板哪個是顯示屏數據線插座 瀏覽:849
5sing上傳音頻文件格式 瀏覽:171
win10輸入文件滑鼠右鍵異常 瀏覽:634
聽幼兒故事用什麼app 瀏覽:514
iphone修改音頻文件名 瀏覽:53
國家氣象站點數據在哪裡下載 瀏覽:342
網路設置的網站 瀏覽:914
手機測量放樣怎麼導數據和線型 瀏覽:648
企業展示型網站源碼 瀏覽:781
易花花app哪裡下載 瀏覽:323
外國程序員職業生涯長 瀏覽:709
看理想app怎麼注銷賬號 瀏覽:545
數控銑床加工手工編程的步驟有哪些 瀏覽:411
uc瀏覽器為什麼很多網站進不了 瀏覽:513
西部數據移動硬碟怎麼 瀏覽:645
批處理修改子目錄文件名命令 瀏覽:405
文件損壞怎麼刪除 瀏覽:977

友情鏈接