Posted By:
Annie_Fran
Posted On:
Wednesday, July 25, 2001 10:20 AM
Hi all!:) 1) Can anybody please tell me how to create a zip file including all files in a subdirectory? I have writting this program wich zip only one file. program: import java.awt.*; import java.io.*; import java.util.*; import java.util.zip.*; import java.util.Date; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream ; public static void VariosArqs() throws FileNotFoundException, IOException { try{ String Path = "C:/arqs"; File Arq = new File(Path); int l=0; String Str[] = (Arq.list()); FileOutputStream zipFilename = new Fi
More>>
Hi all!:)
1) Can anybody please tell me how to create a zip file including all files in a subdirectory? I have writting this program wich zip only one file.
program:
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.util.Date;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream ;
public static void VariosArqs()
throws FileNotFoundException, IOException
{
try{
String Path = "C:/arqs";
File Arq = new File(Path);
int l=0;
String Str[] = (Arq.list());
FileOutputStream zipFilename = new FileOutputStream ("C:/arqs/backup.zip");
ZipOutputStream zipoutputstream = new ZipOutputStream(zipFilename);
zipoutputstream.setMethod(ZipOutputStream.DEFLATED);
if(Arq.exists())
{
int i = 0;
while (i
< Str.length) {
char StrChar[] = Str[i].toCharArray();
int x = StrChar.length;
// seleciona somente os .txt
if ((StrChar[x-3]=='t') && (StrChar[x-2]=='x') && (StrChar[x-1]=='t')){
for (int j = 0; i
< Str[j].length(); j++)
{
File file = new File("C:/arqs/"+Str[j]);
byte [] rgb = new byte [1000];
int n;
FileInputStream fileinputstream;
CRC32 crc32 = new CRC32();
crc32.reset();
fileinputstream = new FileInputStream(file);
while ((n = fileinputstream.read(rgb)) > -1)
{
crc32.update(rgb, 0, n);
}
fileinputstream.close();
// Create a zip entry.
ZipEntry zipentry = new ZipEntry("C:/Projeto/Pgm_Unzip/log/"+Str[j]);
zipentry.setCrc(crc32.getValue());
zipentry.getCrc();
// Add the zip entry and associated data.
System.out.println("aqui");
zipoutputstream.putNextEntry(zipentry);
fileinputstream = new FileInputStream(file);
while ((n = fileinputstream.read(rgb)) > -1)
{
zipoutputstream.write(rgb, 0, n);
}
zipoutputstream.finish();
zipoutputstream.flush();
fileinputstream.close();
zipoutputstream.closeEntry();
zipoutputstream.close();
}
zipoutputstream.close();
}
}
l = l + 1;
i++;
}
}catch (Exception ex){
ex.printStackTrace();
}
}
}
2) Is there a command that zip and move at the same time the files into the zip file? i.e. when I finished zipping, I will have only the zipped file in the directory. Is it possible?
Thanks a lot,
Annie Fran
<<Less