Uploading files to the server
String TempPath = Req.getsession (). Getservletcontext (). Getrealpath ("webresources/templet/");
String filename = Importfile.getoriginalfilename (); @RequestParam ("ImportFile") Commonsmultipartfile ImportFile as a parameter pass the background
Extract zip file
String Zippath = temppath + file.separator + filename;
String zipfolder = filename.substring (0, Filename.length ()-4);
String Decompresspath = temppath + File.separator + zipfolder;
List<string> filepathlist =readbyapachezipfile (Zippath, Decompresspath);
@SuppressWarnings ("unchecked") Public list<string> readbyapachezipfile (string zippath, string decompresspath) t Hrows IOException,
FileNotFoundException, Zipexception {
File F = new file (Decompresspath);
if (!f.exists ()) {
F.mkdirs ();
}
list<string> filepathlist = new arraylist<string> ();
ZipFile ZF = new ZipFile (Zippath, "GBK");/support Chinese
Enumeration<zipentry> e = zf.getentries ();
while (E.hasmoreelements ()) {
ZipEntry ze2 = (zipentry) e.nextelement ();
String entryname = Ze2.getname ();
String Path = Decompresspath + "/" + entryname;
if (Ze2.isdirectory ()) {
SYSTEM.OUT.PRINTLN ("Creating Decompression Directory-" + EntryName);
File Decompressdirfile = new file (path);
if (!decompressdirfile.exists ()) {
Decompressdirfile.mkdirs ();
}
} else {
SYSTEM.OUT.PRINTLN ("Creating unzip file-" + EntryName);
String filedir = path.substring (0, Path.lastindexof ("/"));
File Filedirfile = new file (Filedir);
if (!filedirfile.exists ()) {
Filedirfile.mkdirs ();
}
Bufferedoutputstream BOS = new Bufferedoutputstream (new FileOutputStream (path));
Bufferedinputstream bi = new Bufferedinputstream (Zf.getinputstream (ze2));
byte[] readcontent = new byte[1024];
int readcount = Bi.read (readcontent);
while (Readcount!=-1) {
Bos.write (readcontent, 0, Readcount);
Readcount = Bi.read (readcontent);
}
Bos.close ();
String curdatestr = portalutils.getcurrentdatetimestring ();
String Renamepath = Decompresspath + "/" + entryname.substring (0, Entryname.lastindexof ("/") + 1)
+ Curdatestr + "_" + entryname.substring (Entryname.lastindexof ("/") + 1, entryname.length ());
File FF = new file (path);
Ff.renameto (New File (Renamepath));
Filepathlist.add (Renamepath);
}
}
Zf.close ();
return filepathlist;
}