Results 1 to 11 of 11
  1. #1
    linux1man's Avatar
    linux1man is offline Member
    Join Date
    Nov 2008
    Posts
    39
    Rep Power
    0

    Question Copying a derectory

    Hi,

    I am making a backup program (using JFrameBuilder for the GUI) and i need to know how do you copy a directory to another directory. For example:

    C:\Documents and Settings\Owner\My Documents --> O:\
    (Trying to copy my documents folder to my flash drive)

    I have only taken AP Java in my High School, so i dont know a lot of stuff.
    Anybody please reply

    -- Thanks
    -- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
    -- 2.66 Ghz Pentium Geforce NVidia 440 64mb

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Do you want to do this for Windows or any platform?

    If you want to do this on Windows, use the process class to execute the copy command.

  3. #3
    linux1man's Avatar
    linux1man is offline Member
    Join Date
    Nov 2008
    Posts
    39
    Rep Power
    0

    Default

    windows, but other platforms would be good too.
    -- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
    -- 2.66 Ghz Pentium Geforce NVidia 440 64mb

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually I don't know such a common way for all platforms. So what you have to do is, check the platform first and do the correct process there. Seems to me you are a Linux user, you may know the shell command.

  5. #5
    poroto20 is offline Member
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    0

    Default

    You can do it only with 1 line:

    Java Code:
    FileUtils.copyDirectory(arg0, arg1)
    You have to include commons-io.jar from Apache
    Leandro Iriarte. Systems Engineer
    http://www.leandroiriarte.com.ar

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  7. #7
    poroto20 is offline Member
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    0

    Default

    Sure, but I recommend commons-io.jar
    Leandro Iriarte. Systems Engineer
    http://www.leandroiriarte.com.ar

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  9. #9
    poroto20 is offline Member
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    0

    Default

    It works excellent for me and all most J2EE frameworks use it (Spring for example)
    Leandro Iriarte. Systems Engineer
    http://www.leandroiriarte.com.ar

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  11. #11
    poroto20 is offline Member
    Join Date
    Jan 2009
    Posts
    34
    Rep Power
    0

Similar Threads

  1. copying contents from word document to JTextPane
    By success21061985 in forum Advanced Java
    Replies: 1
    Last Post: 11-05-2008, 07:09 AM
  2. Creating Folder in JAVA and Copying File
    By fnoman in forum New To Java
    Replies: 8
    Last Post: 10-18-2008, 08:33 AM
  3. deep copying arraylist to add to a list
    By alvations in forum New To Java
    Replies: 13
    Last Post: 10-08-2008, 04:13 PM
  4. Copying Eclipse Plugins
    By gapper in forum Eclipse
    Replies: 1
    Last Post: 01-23-2008, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •