关于旗正规则引擎规则中的上传和下载问题

编程技术  /  houtizong 发布于 3年前   167
文件的上传下载都是数据流的输入输出,大致流程都是一样的。
一、文件打包下载
1.文件写入压缩包
string mainPath="D:\upload\";     下载路径

string tmpfileName=jar.zip;             压缩文件名
string lsml=System.getProperty("java.io.tmpdir")+"\";  临时目录
string zipPath=lsml+tmpfileName;        压缩文件下载路径
byte buffer[]=new byte[1024];

file tmpFile=new file(zipPath)
if(!tmpFile.exists()){
    tmpFile.creatNewfile();
}                                       创建压缩文件

FileOutputStream fos=new FileOutputStream(tmpFile);
ZipOutputStream zos=new ZipOutputStream(fos);

File[] file=new File(mainPath+需要下载文件的文件名);

for(i=0;i<file.length;i++){
     FileInputStream fis=new FileInputStream(file[i]);    需要下载的文件读入输入流
zos.putNextEntry(new ZipEntry(file[i].getName()));   文件写入zip中
zos.setEncoding("GBK");
int x=0;
while((x=fis.read(buffer))!=-1){
     zos.write(buff,0,x);
}
zos.closeEntry();
fis.close();
}
zos.close();
fos.close();

2.压缩包下载
File file=new File(zipPath);
if(file.exists()){
     InputStream ins=new InputStream(zipPah);
BuffInputStream bis=new BuffInputStream(ins);
OutputStream outs=response.OutputStream();
BuffOutputStream bos=new BuffOutputStream(outs);
int y=0;
byte[] buffer = new byte[1024];
while((y=bis.read(buffer)!=-1){
     bos.write(buffer,0,y);
}
bos.flush();
ins.close();
bis.close();
outs.close();
bos.close();
}
将以上流程按照设计的需求,写入到相应规则就可以了。
二、文件上传
对于文件上传,flagleader规则引擎中对于的jsp页面中有上传文件的功能,默认会将文件储存到C:\VisualRules\Tomcat\temp目录下

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客