7 Replies Latest reply: Feb 18, 2013 1:19 AM by EJP RSS

    Move Files

      Good Day Experts,

      What is the best method or api for moving files to another directory?
        • 1. Re: Move Files
          you can think of considering FileUtils in commons-io.jar from apache commons.
          • 2. Re: Move Files
            Do this one throw exception if the move fails?

            Because in File.renameTo() only return false but didnt throw any error why it fails.
            • 3. Re: Move Files
              That's correct, it doesn't throw exceptions. java.nio.files.Files throws exceptions. Note that File.renameTo() won't move a file across filesystems, only rename within or between directories on the same file system.
              • 4. Re: Move Files
                So you mean it's better to use the apache?
                • 5. Re: Move Files
                  So you mean ...
                  No, I don't mean ...

                  Whenever, and I do mean whenever, I see a question that starts like that, the answer is invariably 'no'.

                  This time is no exception.

                  I haven't said one single word about Apache.
                  • 6. Re: Move Files
                    here is the API

                    http://commons.apache.org/io/api-release/org/apache/commons/io/FileUtils.html#copyDirectory(java.io.File, java.io.File)

                    Give it a shot and see if it full fills all your needs if it doesn't try something else.
                    • 7. Re: Move Files
                      Surely you mean moveFileToDirectory(), although it is hard to make much sense of statements like this: 'createDestDir - If true create the destination directory, otherwise if false throw an IOException'.