MigrationFilePackOperation.jsp
4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<%@ page import="weaver.general.GCONST" %><%@ page import="java.util.List" %><%@ page import="java.util.ArrayList" %><%@ page import="java.io.*" %><%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.json.JSONObject" %><% String rootpath=GCONST.getRootPath();
new BaseBean().writeLog("开始打包文件");
String filePath=rootpath+File.separatorChar+"system"+File.separatorChar+"upgradetoe9"+File.separatorChar+"report"+File.separatorChar+"migrationFile.txt";
File file=new File(filePath);
JSONObject jsonObject=new JSONObject();
if(!file.exists() || !file.isFile()){//如果文件不存在的话,或则文件不是一个文件的话,不做任何操作
new BaseBean().writeLog("迁移文件列表未找到");
jsonObject.put("status","0");
jsonObject.put("msg","迁移文件列表未找到");
}else{
new BaseBean().writeLog("打包文件找到");
FileReader fr=new FileReader(file);
BufferedReader bufferedReader=new BufferedReader(fr);
List<String> pathlist=new ArrayList<String>();
String str=null;
while ((str=bufferedReader.readLine())!=null){
new BaseBean().writeLog(rootpath+str);
File file1=new File(rootpath+str);
if(file1==null ||!file1.exists() || !file1.isFile()){
new BaseBean().writeLog("打包文件未找到");
continue;
}
pathlist.add(rootpath+str);
}
pathlist.add(filePath);
if(bufferedReader!=null){
bufferedReader.close();
}
if(fr!=null){
fr.close();
}
wscheck.ZipUtils.execute(pathlist, GCONST.getRootPath()+"filesystem"+File.separatorChar+"scanecologyzip"+".zip",rootpath,"ecology");
File allecologyzip = new File(GCONST.getRootPath()+"filesystem"+File.separatorChar+"scanecologyzip"+".zip");
if(!allecologyzip.exists()){
jsonObject.put("msg","文件未打包成功");
}else{
jsonObject.put("status","1");
}
response.getWriter().print(jsonObject.toString());
// {
// InputStream ins=null;
// BufferedInputStream bins=null;
// OutputStream outs=null;
// BufferedOutputStream bouts=null;
// try
// {
// response.reset();
// ins=new FileInputStream(allecologyzip);
// bins=new BufferedInputStream(ins);//放到缓冲流里面
// outs=response.getOutputStream();//获取文件输出IO流
// bouts=new BufferedOutputStream(outs);
// response.setBufferSize(0);
// response.setContentType("application/x-download");//设置response内容的类型
// response.setHeader("Content-disposition","attachment;filename=\"scanecologyzip.zip");//设置头部信息
// //response.addHeader("Content-Length", "" + newecologyzip.length());
// int bytesRead = 0;
// byte[] buffer = new byte[8192];
// //开始向网络传输文件流
// while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
// bouts.write(buffer, 0, bytesRead);
// bouts.flush();
// }
// bouts.flush();//这里一定要调用flush()方法
// outs.flush();
// ins.close();
// bins.close();
// outs.close();
// bouts.close();
// allecologyzip.delete();
// }
// catch (Exception ef)
// {}
// finally
// {
// if(ins!=null) ins.close();
// if(bins!=null) bins.close();
// if(outs!=null) outs.close();
// if(bouts!=null) bouts.close();
// if(bufferedReader!=null){
// bufferedReader.close();
// }
// if(fr!=null){
// fr.close();
// }
// }
// }
}
%>