當前位置:首頁 » 編程語言 » java伺服器下載

java伺服器下載

發布時間: 2024-07-14 06:54:42

❶ 怎麼使用java完成下載excel文件,伺服器上excel文件是直接存在的而不是導出的(必須使用action)

寫個文件專門提供下載文件也可以,但那樣對於你這種情況明顯多餘了,把伺服器端Excel文件的MIME類型映射信息改成application/octet-stream即可。這個映射可以在web.xml中定義。

❷ java從伺服器下載圖片怎麼講圖片保存到本地的sdcard上

ublic HttpServletResponse download(String path, HttpServletResponse response) {
try {
// path是指欲下載的文件的路徑。
File file = new File(path);
// 取得文件名。
String filename = file.getName();
// 取得文件的後綴名。
String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();

// 以流的形式下載文件。
InputStream fis = new BufferedInputStream(new FileInputStream(path));
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
// 清空response
response.reset();
// 設置response的Header
response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
response.addHeader("Content-Length", "" + file.length());
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
toClient.write(buffer);
toClient.flush();
toClient.close();
} catch (IOException ex) {
ex.printStackTrace();
}
return response;
}

❸ JAVA中如何將文件上傳到伺服器以供下載

<a href="app的路徑">點擊下載xxx.app</a>

❹ java怎樣讀取http文件伺服器上的文件列表並下載

把要下載的文件名存在資料庫中,載入頁面通過servlet或者action或者採用javaBean讀取資料庫數據,然後遍歷出來,再通過servlet或者action的outputstream下載即可

❺ 高分:用java實現伺服器上多個文件先打包,然後下載,下載完成後刪除包!

壓縮包里添加文件時直接把伺服器上的文件用流讀進來就行,不用非把文件放到同一個目錄,用程序生成壓縮包和用命令行工具是不一樣的,不要想當然。 寫了個示常式序,你可以參考一下。這個示例不使用臨時文件,把 OutputStream os替換成你下載用的輸出流就可以實現一邊壓縮一邊下載。注意java.util.zip不支持非ascii文件名。想支持中文文件名可以用apache ant或其他的庫。

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipTest {

public static void main( String[] args ) {
try {
writeZip();
} catch ( IOException e ) {
e.printStackTrace();
}
}

private static void writeZip() throws IOException {
String[] files = { "/ws/dir1/file1", "/ws/dir2/file2", "/ws/file3", "/pub/success.wav" };
OutputStream os = new BufferedOutputStream( new FileOutputStream( "/ws/archive.zip" ) );
ZipOutputStream zos = new ZipOutputStream( os );
byte[] buf = new byte[8192];
int len;
for ( String filename : files ) {
File file = new File( filename );
if ( !file.isFile() ) continue;
ZipEntry ze = new ZipEntry( file.getName() );
zos.putNextEntry( ze );
BufferedInputStream bis = new BufferedInputStream( new FileInputStream( file ) );
while ( ( len = bis.read( buf ) ) > 0 ) {
zos.write( buf, 0, len );
}
zos.closeEntry();
}
zos.close();
}

}

❻ java如何實現從伺服器下載已經生成好的excel文件

使用 HttpURLConnection 去下載 ,按二進制保存文件 ~~~~~~~~~

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:585
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:881
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:574
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:761
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:677
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1005
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:249
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:108
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:799
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:705