Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7907649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:33:21+00:00 2026-06-03T11:33:21+00:00

A program we have erred when trying to move files from one directory to

  • 0

A program we have erred when trying to move files from one directory to another. After much debugging I located the error by writing a small utility program that just moves a file from one directory to another (code below). It turns out that while moving files around on the local filesystem works fine, trying to move a file to another filesystem fails.

Why is this? The question might be platform specific – we are running Linux on ext3, if that matters.

And the second question; should I have been using something else than the renameTo() method of the File class? It seems as if this just works on local filesystems.

Tests (run as root):

touch /tmp/test/afile

java FileMover /tmp/test/afile /root/
The file move was successful

touch /tmp/test/afile

java FileMover /tmp/test/afile /some_other_disk/
The file move was erroneous

Code:

import java.io.File;

public class FileMover {
    public static void main(String arguments[] ) throws Exception {
        boolean success;
        File file = new File(arguments[0]);
        File destinationDir = new File(arguments[1]);
        File destinationFile = new File(destinationDir,file.getName() );
        success = file.renameTo(destinationFile);
        System.out.println("The file move was " + (success?"successful":"erroneous"));
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:33:22+00:00Added an answer on June 3, 2026 at 11:33 am

    Java 7 and above

    Use Files.move(Path source, Path target, CopyOption... opts).

    Note that you must not provide the ATOMIC_MOVE option when moving files between file systems.

    Java 6 and below

    From the docs of File.renameTo:

    […] The rename operation might not be able to move a file from one filesystem to another […]

    The obvious workaround would be to copy the file “manually” by opening a new file, write the content to the file, and delete the old file.

    You could also try the FileUtils.moveFile method from Apache Commons.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For this program i have only used field separators from data files in shell
I currently have a catalog of files I want to read into my program
In my program I have one array with 25 double values 0.04 When I
I have manualy writing class for WinSock. My program have more that one threads.
I have program with two files; main.py that has my main logic and class.py
I have a program that roughly does this: open a file to read from
The program have to download data from MySQL database. and fill the JList .
I have program that has a variable that should never change. However, somehow, it
I have program, that must interact with a console program before my program can
I have program that runs fast enough. I want to see the number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.