spingmvc 文件下载打包zip
2016-12-20 10:39
351 查看
先缓存到File对象数组,再保存传流:
public Object doFileDownload(String id_src, OutputStream outputStream) throws IOException { HDFSUtils hdfsUtils = new HDFSUtils(); String[] id_src_array = id_src.split(","); if (id_src_array.length > 10) { JSONObject result = new JSONObject(); result.put("result", "0"); result.put("desc", "Download file overran by ten flles!"); return result; } else if (id_src_array.length == 1) { String download_url = doQueryFilePath(id_src); String hdfsPath = root_dir + download_url; InputStream inputStream = hdfsUtils.downLoadFile(id_src, hdfsPath); byte[] b = new byte[4096]; int length; while ((length = inputStream.read(b)) > 0) { outputStream.write(b, 0, length); } outputStream.close(); inputStream.close(); return null; } else { ZipOutputStream out = new ZipOutputStream(new FileOutputStream("report.zip")); File[] file = new File[id_src_array.length]; byte[] buffer = new byte[4096]; for (int i = 0; i < id_src_array.length; i++) { file[i] = new File(id_src_array[i]); } for (int i = 0; i < file.length; i++) { String download_url = doQueryFilePath(id_src_array[i]); String hdfsPath = root_dir + download_url; InputStream inputStream = hdfsUtils.downLoadFile(id_src, hdfsPath); out.putNextEntry(new ZipEntry(download_url.split("/")[download_url.split("/").length - 1])); int len; while ((len = inputStream.read(buffer)) > 0) { out.write(buffer, 0, len); } out.closeEntry(); inputStream.close(); } out.close(); File file1 = new File("report.zip"); InputStream inputStream = new FileInputStream(file1); byte[] b = new byte[1024]; int length; while ((length = inputStream.read(b)) > 0) { outputStream.write(b, 0, length); } inputStream.close(); return null; } }
相关文章推荐
- Java实现文件自动打包成zip并下载的代码
- ThinkPHP实现将本地文件打包成zip下载
- 使用PHP自带zlib函数 几行代码实现PHP文件打包下载zip
- 【Java】Java实现批量打包文件Zip下载
- springmvc批量将文件打包成zip下载
- 文件zip打包,流式下载python 代码
- 使用PHP的ZipArchive类实现多个文件的zip压缩包打包下载
- 生成的Excel出力到指定文件夹生成Zip文件再打包这些文件到页面下载
- zip压缩打包文件下载
- [Java Web]服务器获取远程文件并Zip打包给客户端下载
- Java实现文件自动打包成zip并下载的代码
- 使用PHP自带zlib函数 几行代码实现PHP文件打包下载zip
- struts zip打包多个文件并下载
- ajax下载多文件,并且打包 C#中 ,文件批下载zip
- java 将多个文件打包成一个zip后进行下载
- ThinkPHP实现将本地文件打包成zip下载
- Java打包下载ZIP压缩文件
- meteor---在合并打包多个文件ZIP下载的功能
- 几行代码轻松实现PHP文件打包下载zip
- spring mvc java 把多文件打包成zip,并下载