Published 2008. 7. 20. 19:41
일반적으로 웹에서 ActiveX를 사용하지 않는 이상 멀티 다운로드는 불가능하다고 봐야 합니다.
저도 여러가지 방법을 생각해 보고 구현도 해봤지만 업로드는 멀티 업로드가 되는대 
다운로드 같은 경우는 울며 겨자먹기로 ActiveX를 사용하거나 아니면 
다운로드할 파일들을 서버에서 압축하여 압축된 파일을 다운로드 하는 방법 뿐이 현제로써는
가장 좋은 방법일거 같습니다. 
아래 소스는 실제 구현했던 소스중 서버에서 파일 압축하는 로직만 분리한것 입니다.
궁금하신사항 있으면 댓글 달아 주세요.
===========================================================================================
jdk 5 에서 기본 지원하는 
java.util.zip.ZipEntry;
java.util.zip.ZipOutputStream;
도 있으나 테스트 결과 output 으로 나오는 .zip 파일은 한글이
정상적으로 나오나 압축 파일안에 있는 한글 파일들이 깨짐;;;
그래서 첨부파일 있는 ant.jar 를 이용해서 해결
import org.apache.tools.zip.ZipEntry; //ant.jar 이용
import org.apache.tools.zip.ZipOutputStream; //ant.jar 이용
public boolean fileCompress(String filePath, String compressFile, String fileNm) {
// File dir = new File("c:\\temp");
String[] fnames = fileNm.split("\\|");
try{
byte[] bytes = new byte[8192];
String targetName = filePath+"/"+compressFile;
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(targetName));
for(int i=0; i<fnames.length; i++){
System.out.println(fnames[i]);
FileInputStream fis = new FileInputStream(filePath+"/"+fnames[i]);
zos.putNextEntry(new ZipEntry(fnames[i]));
int len = 0;
while((len = fis.read(bytes))>0)
{
zos.write(bytes, 0, len);
}
zos.closeEntry();
fis.close();
}
zos.close();
}catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}

ant.jar


복사했습니다!