🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1365

How to zip up directory?

#1365
From: Alex Colic
Date: Thu, 31 Jan 2002 16:39
73 lines
2646 bytes
Hi,

I am trying to zip up a directory. So far I have the below code but I get an
error when trying to open the input stream. Could someone suggest how I can
get this to work please. CRLCA is the directory.

Thanks

Alex

private boolean zipUpFile(File backupDir)
{
  boolean zipped=false;

  ZipOutputStream targetStream = null;
  BufferedInputStream sourceStream=null;

  try
    {
        targetStream = new ZipOutputStream(new
        FileOutputStream(backupdirectory + seperator + "CRLCA.zip" ));
        String filename = backupdirectory + seperator + "CRLCA";

        File f = new File(filename);
        FileInputStream fin=new FileInputStream(f);
        ZipEntry theEntry = new ZipEntry(filename);
        if (f.isDirectory())
          {
              targetStream.setComment("Backup of Database on: " + new
java.util.Date(System.currentTimeMillis()));
              targetStream.setMethod(ZipOutputStream.DEFLATED);
              targetStream.setLevel(9);
              targetStream.putNextEntry(theEntry);
              StreamCopier(fin, targetStream);
              targetStream.closeEntry();
              fin.close();

          }
    }
    catch (Exception ex)
      {
      System.out.println(ex);
      }
    finally
    {
      try
        {
            if (targetStream != null) targetStream.close();
        }
      catch (Exception ex) {}
    }

return zipped;
}

private static void StreamCopier(InputStream in, OutputStream out) throws
IOException
{
  synchronized(in)
  {
    synchronized(out)
    {
      byte [] buffer=new byte[1024];
      while(true)
      {
        int bytesRead=in.read(buffer);
        if(bytesRead==-1)break;
        out.write(buffer,0,bytesRead);
      }

    }
  }
}
Technical Details
Message-ID: <3c5972ae_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!isdnet!proxad.net!proxad.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!dnews

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,eb23576af1c5e5db,start
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-01-31 08:41:51 PST
From: "Alex Colic" <Alex.Colic@pop-ware.com>
Newsgroups: borland.public.jbuilder.java.api
Subject: How to zip up directory?
Date: Thu, 31 Jan 2002 11:39:13 -0500
Lines: 76
Organization: PopWare Inc
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
NNTP-Posting-Host: 24.150.151.67
Message-ID: <3c5972ae_2@dnews>
X-Trace: dnews 1012495022 24.150.151.67 (31 Jan 2002 08:37:02 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!isdnet!proxad.net!proxad.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!dnews