java文件流的处理文件打包成zip

java⽂件流的处理⽂件打包成zip 1、下载⽂件到本地
public void download(HttpServletResponse response){
颜面除皱String filePath ="";//⽂件路径
String fileName ="";//⽂件名称
// 读到流中
InputStream inStream = new FileInputStream(filePath);
// 设置输出的格式
response.setContentType("bin");
response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
中华人民共和国营业税暂行条例实施细则
}
2、java后端下载
⽅式⼀:
new URL(fileUrl + BhFileserver()).openStream()
⽅法⼆:
public Boolean addFile(String url, String id, String fileName) {
RequestCallback requestCallBack = new RequestCallback() {
@Override
public void doWithRequest(ClientHttpRequest request) throws IOException {
}
};
ResponseExtractor<Boolean> responseExtractor = new ResponseExtractor<Boolean>() {
@Override
public Boolean extractData(ClientHttpResponse response) throws IOException {
if (StatusCode() == HttpStatus.OK) {
//得到⽂件流
InputStream input = Body();
return true;
}
return false;
}
};
ute(url, HttpMethod.GET, requestCallBack, responseExtractor, id);
}
3、⽂件打包成zip
public void zipFilesAll() throws Exception {
String zipPath = "";//zip包路径
String zipFileName = "";//zip包名称
File zipFile = new File(zipFileName .toString());
// 创建 FileOutputStream 对象
FileOutputStream fileOutputStream = null;
// 创建 ZipOutputStream
ZipOutputStream zipOutputStream = null;
try {
//创建⽂件夹
zipFile = new File(zipPath );
FileUtils.forceMkdir(zipFile);
//创建⽂件单循环赛
金融时报中文zipFile = new File(zipFileName .toString());
if (!ists()) {
中国日报中文版
}
// 实例化 FileOutputStream 对象
fileOutputStream = new String());
// 实例化 ZipOutputStream 对象
zipOutputStream = new ZipOutputStream(fileOutputStream);
// 创建 ZipEntry 对象
ZipEntry zipEntry = null;
《国家新型城镇化规划(2014-2020年)》for (CL cl: ClList) {
// 实例化 ZipEntry 对象,源⽂件数组中的当前⽂件
zipEntry = new Clmc() + ".zip");
zipOutputStream.putNextEntry(zipEntry);
} catch (Exception e) {
}finally{
//记得删除⽂件
}
}

本文发布于:2024-09-21 00:44:11,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/158759.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:创建   营业税   输出   规划   打包   读到   记得   暂行条例
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议