Results 1 to 2 of 2
  1. #1
    Aiden is offline Member
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Red face Moving file to another folder

    Hi forum,

    I am a newbie to java. I'm stuck with this problem. I would like to move list of files from one folder to another folder. Can anyone give me a head start...Below is my code but this only moves a single file. How can i move multiple files?? Interate??Array??

    If you know a tutorial about this, please provide the hyperlink.


    Java Code:
     public static void moveFile() {
    
           try {
    
               // File (or Directory) to be moved
              File cFile = new File("C:/FolderA/[B]file.txt[/B]");
              // Destination directory
              File dir = new File("C:/FolderB");
    
              // Move file to a new directory
              boolean success = cFile.renameTo(new File(dir, cFile.getName()));
                System.out.println("Success::"+cFile.renameTo(new File(dir, cFile.getName())));
    
                if (success) {
                    System.out.println("File was successfully moved.\n");
                } else {
                    System.out.println("File was not successfully moved.\n");
                }
    
            } catch (Exception ex) {
    
                System.out.println(ex);
            }
        }
    Thanks

    Aiden

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

Similar Threads

  1. moving a file
    By swati.jyoti in forum New To Java
    Replies: 8
    Last Post: 11-23-2009, 08:44 AM
  2. need to get the file name from folder
    By naveen.dpt2007 in forum New To Java
    Replies: 2
    Last Post: 09-04-2009, 06:57 PM
  3. Copy a file to a folder.
    By leric in forum New To Java
    Replies: 7
    Last Post: 07-29-2009, 05:11 AM
  4. [SOLVED] File is Not Moving
    By jazz2k8 in forum New To Java
    Replies: 7
    Last Post: 07-07-2008, 10:58 AM
  5. moving a file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-10-2007, 07:52 PM

Posting Permissions

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