The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.io  [35 examples] > Files  [9 examples]

e25. Moving a File or Directory to Another Directory

    // 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
    }

 Related Examples
e19. Determining If a File or Directory Exists
e20. Creating a File
e21. Getting the Size of a File
e22. Deleting a File
e23. Creating a Temporary File
e24. Renaming a File or Directory
e26. Getting and Setting the Modification Time of a File or Directory
e27. Forcing Updates to a File to the Disk

See also: Directories    Encodings    Filenames and Pathnames    Parsing    Reading and Writing    Serialization   


© 2002 Addison-Wesley.