Results 1 to 3 of 3
  1. #1
    Leprechaun is offline Member
    Join Date
    Dec 2007
    Posts
    30
    Rep Power
    0

    Default [SOLVED] File Movement/Manipulation

    I was wondering what class or classes I should use to move files. I'm looking to find all the files/folders in a directory and move them to a new location. Consequently I'll need to a way to find all the files/folders in a folder.

    Thanks for any help.

  2. #2
    rico16135 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    Java Code:
    // File (or directory) to be moved
        File file = new File("filename");
        
        // Destination directory
        File dir = new File("directoryname");
        
        // Move file to new directory
        boolean success = file.renameTo(new File(dir, file.getName()));
        if (!success) {
            // File was not successfully moved
        }

    -------------------------------------------------------------
    that should move them, here's how to find them
    -------------------------------------------------------------



    Java Code:
    import java.io.File;
    
    public class DirectoryReader {
    
      public static void main(String[] args) {
    
        File folder = new File("c:/");
        File[] listOfFiles = folder.listFiles();
    
        for (int i = 0; i < listOfFiles.length; i++) {
          if (listOfFiles[i].isFile()) {
            System.out.println("File " + listOfFiles[i].getName());
          } else if (listOfFiles[i].isDirectory()) {
            System.out.println("Directory " + listOfFiles[i].getName());
          }
        }
      }
    
    }

  3. #3
    Leprechaun is offline Member
    Join Date
    Dec 2007
    Posts
    30
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 04-07-2009, 07:25 AM
  2. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 10:13 AM
  3. String manipulation example (Title case)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-29-2008, 10:04 AM
  4. Movement of balls
    By BlitzA in forum New To Java
    Replies: 8
    Last Post: 01-09-2008, 04:30 PM
  5. String Manipulation Task
    By hiranya in forum New To Java
    Replies: 1
    Last Post: 11-19-2007, 12:07 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
  •