主题:  unzip a file in cfmx with java

s22

职务:版主
等级:4
金币:10.0
发贴:1634
注册:2004/12/19 13:06:46
#12003/7/30 0:05:08


function unzipFile(zipFilePath, outputPath) {

var zipFile = ""; // ZipFile
var entries = ""; // Enumeration of ZipEntry
var entry = ""; // ZipEntry
var fil = ""; //File
var filOutStream = "";
var bufOutStream = "";
var nm = "";
var pth = "";
var lenPth = "";

zipFile = createObject("java", "java.util.zip.ZipFile");
zipFile.init(zipFilePath);

entries = zipFile.entries();

while(entries.hasMoreElements()) {
entry = entries.nextElement();

if(NOT entry.isDirectory()) {
nm = entry.getName();

lenPth = len(nm) - len(getFileFromPath(nm));

if (lenPth) {
pth = outputPath & left(nm, lenPth);
} else {
pth = outputPath;
}

if (NOT directoryExists(pth)) {
fil = createObject("java", "java.io.File");
fil.init(pth);
fil.mkdirs();
}

filOutStream = createObject(
"java",
"java.io.FileOutputStream");

filOutStream.init(outputPath & nm);

bufOutStream = createObject(
"java",
"java.io.BufferedOutputStream");

bufOutStream.init(filOutStream);

copyInputStream(
zipFile.getInputStream(entry),
bufOutStream);
}
}

zipFile.close();
}

function copyInputStream(inStream, outStream) {

var buffer = repeatString(" ",1024).getBytes();
var l = inStream.read(buffer);

while(l GTE 0) {
outStream.write(buffer, 0, l);
l = inStream.read(buffer);
}
inStream.close();
outStream.close();
}






suzzledboy

职务:普通成员
等级:1
金币:1.0
发贴:225
注册:2001/6/21 19:07:00
#22003/8/1 9:43:22
干什么用的?