I want to copy a zip file from one folder to another folder in java.
i have a migrate.zip file in sourcefolder .i need to copy that migrat.zip file to destination folder.
can any one help me on this.
Thanks&Regards, sivakrishna.m
I want to copy a zip file from one folder to another folder in java.
i have a migrate.zip file in sourcefolder .i need to copy that migrat.zip file to destination folder.
can any one help me on this.
Thanks&Regards, sivakrishna.m
apache-commons-io library is helpful in you problem
org.apache.commons.io.FileUtils.copyFile(File, File)
FileUtils.copyFile(new File("/sourcefolder/migrate.zip"),
new File("/destination/migrate.zip"))
Please check the below question and answer. This may help you.
try this set of lines.
String sourceFilePath =" Source path";
File f = new File(sourceFilePath);
File f1 = new File(destinationFilePath);
File fCopy = new File(destinationFilePath);
if (f1.exists()) {
// Don't do anything..
f1.delete();
}
FileUtils.copyFile(f, fCopy)
Use java.util.ZipInputStream class to read migrate.zip file from source folder and use java.util.ZipOutputStream class to write migrate.zip to the destination folder....
public class CopyZip
{
public static void main(String[] args)
{
FileInputStream fin = new FileInputStream(new File("source_folder\migrate.zip"));
ZipInputStream zin = new ZipInputStream(fin);
byte[] in_bytes = new bytes[1000];
zin.read(in_bytes,0,1000);
FileOutputStream fout = new FileOutputStream(new File("dest_folder\migrate.zip"));
ZipOutputSrream zout = new ZipOutputStream(fout);
zout.write(in_bytes,0,in_bytes.length);
}
}