[Advanced-java] Query on Zipping of file??
Bikash Paul
bikashpaul_2001 at yahoo.com
Thu Jul 3 08:47:36 2003
Hi all friends,
Iam zipping file through my swing interface and
showing the progress of zipping on ProgressMonitor.Iam
selecting file by opening FileDialog box on the action
event of button,Now my problem is when iam selecting
file from my hard disk through FileDialog box for zip,
my whole swing interface and ProgressMonitor going to
disable and after completion of zipping both are
enable.Can any one plz guide me how I can slove this
problem.Below r my codes.
//Button action Event
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
FileDialog fileDialog = new FileDialog(Mac_Zip1.this
);
fileDialog.setMode(FileDialog.LOAD);
fileDialog.show();
if (fileDialog.getFile() == null)
{
return;
}
f = new File(
fileDialog.getDirectory(),fileDialog.getFile());
String aa1=fileDialog.getDirectory();
String aa2=fileDialog.getFile();
int o=aa2.indexOf(".");
String aa3=aa2.substring(0, o);
String a=aa1+aa2;
try {
File myDir =new File(aa1);
ZipOutputStream outStream = new ZipOutputStream (new
FileOutputStream("d:\\DTMS\\Input\\"+aa3+".zip"));
outStream.setMethod(ZipOutputStream.DEFLATED);
outStream.setLevel(9);
processFile(myDir,null, aa2 ,outStream);
JOptionPane.showMessageDialog( null, "ZIPING COMPLETE"
);
outStream.setLevel(9);
}catch(Exception h){ h.printStackTrace();}
}
});
//Method of zipping file
public static void processFile(File myDir, Component
parentComponent,String fileName,ZipOutputStream out)
{
try
{
File f = new File(myDir, fileName);
int length=(int)f.length();
ProgressMonitor monitor = new
ProgressMonitor(parentComponent,"Unpacking " +
f.getName() + "...", "", 0, length);
monitor.setMillisToDecideToPopup(0);
monitor.setMillisToPopup(0);
FileInputStream in = new FileInputStream(f);
// Add ZIP entry to output stream.
ZipEntry e1 = new ZipEntry(fileName);
out.putNextEntry(e1);
monitor.setNote(e1.getName());
byte[] buf = new byte[16384];
int len;
int count=0;
while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
count += len;
monitor.setProgress(count);
}
out.closeEntry();
in.close();
}
catch (Exception e){System.out.println("Error ::" +
e);}
}
Regards
Bikash
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com