help me! how can i copy all files from one directory to another in java

Discussion in 'Java' started by Kulbir, Dec 22, 2005.

  1. Kulbir

    Kulbir Guest

    Hi ,
    can any body help me, how i can copy all files from one directory to
    another in java. suppose i have a source directory called abc/def in
    which i have 20 files. i want to copy all the files from this direcory
    to xxx/yyy directory. can any body suggest me by code sample.
    thanks
     
    Kulbir, Dec 22, 2005
    #1
    1. Advertising

  2. Kulbir

    Guest

    , Dec 22, 2005
    #2
    1. Advertising

  3. Kulbir

    zero Guest

    "Kulbir" <> wrote in news:1135255705.007520.164500
    @f14g2000cwb.googlegroups.com:

    > Hi ,
    > can any body help me, how i can copy all files from one directory to
    > another in java. suppose i have a source directory called abc/def in
    > which i have 20 files. i want to copy all the files from this direcory
    > to xxx/yyy directory. can any body suggest me by code sample.
    > thanks
    >


    First you use File:list() to get all files in the directory. Then, you can
    use FileChannel:transferTo to copy the file.

    FileChannel in = new FileInputStream(fFile).getChannel();
    FileChannel out = new FileOutputStream(fDest).getChannel();

    in.transferTo(0, in.size(), out);


    --
    Beware the False Authority Syndrome
     
    zero, Dec 22, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TJS
    Replies:
    1
    Views:
    547
    Eliyahu Goldin
    Jun 23, 2004
  2. Replies:
    1
    Views:
    609
    Evertjan.
    Sep 30, 2005
  3. imh bychua
    Replies:
    2
    Views:
    546
  4. Replies:
    1
    Views:
    191
    Evertjan.
    Sep 30, 2005
  5. Gerrit Horeis
    Replies:
    1
    Views:
    139
    Thomas 'PointedEars' Lahn
    Aug 12, 2004
Loading...

Share This Page