-1

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

sivakrishna
  • 45
  • 2
  • 5

4 Answers4

1

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"))
Ilya
  • 29,135
  • 19
  • 110
  • 158
0

Please check the below question and answer. This may help you.

Best Way to copy a Zip File via Java

Community
  • 1
  • 1
Ramaraj Karuppusamy
  • 2,350
  • 5
  • 24
  • 35
0

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)
KhAn SaAb
  • 5,248
  • 5
  • 31
  • 52
-1

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);
  }
}
Pavan Kumar K
  • 1,360
  • 9
  • 11