copying five different serialized files in one go itself
<p>I have to make a program to copy the serialized files from a source folder to target folder  </p>

<p>source folder is C:\ter\  (it have 5 different serialized files gfr.ser,asd.ser,hgf.ser,kiu.ser,uew.ser)
target folder is C:\bvg\</p>

<p>files to be transferred are gfr.ser,asd.ser,hgf.ser,kiu.ser,uew.ser</p>

<p>I have come up with this below program but it copies only one serialized file gfr.ser only ,please advise how can I copy all the five serialized files in one go
itself .</p>

<pre><code>  class ScheduledTask extends TimerTask {

        public void run() {
            InputStream inStream = null;
            OutputStream outStream = null;
            try {
                File source = new File("C:\\ter\\");
                File target = new File(" C:\\bvg\\");


                  if (target.exists()){   // Already exists. do not copy
                     return;
                }
               File[] files = source.listFiles();
               for(File file:files){   
                   inStream = new FileInputStream(file);
                    outStream = new FileOutputStream(target);
                       }

                byte[] buffer = new byte[1024];
                int length;
                // copy the file content in bytes
                while ((length = inStream.read(buffer)) &gt; 0) {
                    outStream.write(buffer, 0, length);
                }
                inStream.close();
                outStream.close();
                System.out.println("File is copied successful!");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public class Copycache {
        public static void main(String args[]) throws InterruptedException {
            Timer time = new Timer();
        ScheduledTask task = new ScheduledTask();
        time.schedule(task, new Date(), TimeUnit.SECONDS.toMillis(1));
        }

    }
</code></pre>

<p>I have come up with this approach but still it is not working please advise as the files are finally not get copied...below the stacktrace ...</p>

<pre><code>java.io.FileNotFoundException: C:\bvg\ (Access is denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.&lt;init&gt;(Unknown Source)
    at java.io.FileOutputStream.&lt;init&gt;(Unknown Source)
    at com.bvb.ScheduledTask.run(Copycache.java:31)
    at java.util.TimerThread.mainLoop(Unknown Source)
    at java.util.TimerThread.run(Unknown Source)
</code></pre>
