import javaio;
import javautilzipZipEntry;
import javautilzipZipOutputStream;
public class ZipTest {
public static void main( String[] args ) {
try {
writeZip();
} catch ( IOException e ) {
eprintStackTrace();
}
}
private static void writeZip() throws IOException {
String[] files = { "/ws/dir1/file1", "/ws/dir2/file2", "/ws/file3", "/pub/successwav" };
OutputStream os = new BufferedOutputStream( new FileOutputStream( "/ws/archivezip" ) );
ZipOutputStream zos = new ZipOutputStream( os );
byte[] buf = new byte[8192];
int len;
for ( String filename : files ) {
File file = new File( filename );
if ( !fileisFile() ) continue;
ZipEntry ze = new ZipEntry( filegetName() );
zosputNextEntry( ze );
BufferedInputStream bis = new BufferedInputStream( new FileInputStream( file ) );
while ( ( len = bisread( buf ) ) > 0 ) {
zoswrite( buf, 0, len );
}
zoscloseEntry();
}
zosclose();
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)