/**
FormFile fl = jRailsForm.getFormFile("Filedata");//文件
InputStream fldata;
try {
fldata = fl.getInputStream();
FileInputStream data=(FileInputStream) fldata;
Ectract(data, "/hr/themes/"); // 返回解压缩出来的文件列表
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
*/
/**
* 解压缩
* @param sZipPathFile 要解压的文件
* @param sDestPath 解压到某文件夹
* @return
*/
public void Ectract(FileInputStream data, String sDestPath) {
ArrayList<String> allFileName = new ArrayList<String>();
try {
// 先指定压缩档的位置和档名,建立FileInputStream对象
FileInputStream fins = data;
// 将fins传入ZipInputStream中
ZipInputStream zins = new ZipInputStream(fins);
ZipEntry ze = null;
byte[] ch = new byte[256];
while ((ze = zins.getNextEntry()) != null) {
File zfile = new File(sDestPath +File.separator+ ze.getName());
File fpath = new File(zfile.getParentFile().getPath());
if (ze.isDirectory()) {
if (!zfile.exists())
zfile.mkdirs();
zins.closeEntry();
} else {
if (!fpath.exists())
fpath.mkdirs();
FileOutputStream fouts = new FileOutputStream(zfile);
int i;
allFileName.add(zfile.getAbsolutePath());
while ((i = zins.read(ch)) != -1)
fouts.write(ch, 0, i);
zins.closeEntry();
fouts.close();
}
}
fins.close();
zins.close();
} catch (Exception e) {
System.err.println("Extract error:" + e.getMessage());
}
// return allFileName;
}