// File to copy the files from client machine to server machine

package extractor;

import java.io.*;
import javax.swing.*;

public class MovingFile{

  public static void copyDirectory(File srcDir, File dstDir) throws IOException
	  {
 			System.out.println("srcDir "+srcDir);
 			System.out.println("dstDir "+dstDir);
			try
	  		   {

		           if (srcDir.isDirectory())
					   {
						 if (!dstDir.exists())
                            dstDir.mkdir();

				         String[] children = srcDir.list();
		                 for (int i=0; i<children.length; i++)
							 {
			                     copyDirectory(new File(srcDir, children[i]),
                                 new File(dstDir, children[i]));
                             }
					   }
				   else
				     {
                        copyFile(srcDir, dstDir);
					 }
			   }
			catch (Exception e)
			{
				e.printStackTrace();
			}
      }

    public static void copyFile(File src, File dst) throws IOException
		{
			InputStream in = new FileInputStream(src);
			OutputStream out = new FileOutputStream(dst);

// Transfer bytes from in to out

	        byte[] buf = new byte[1024];
		    int len;
			while ((len = in.read(buf)) > 0)
				{
                   out.write(buf, 0, len);
                }
			in.close();
			out.close();
        }

}