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

文件的上传下载都是数据流的输入输出,大致流程都是一样的。
一、文件打包下载
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目录下

猜你喜欢

转载自1990994609.iteye.com/blog/2224008