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 7703511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:28:34+00:00 2026-05-31T23:28:34+00:00

I want to move some file to other place, using Java SE 1.6 So,

  • 0

I want to move some file to other place, using Java SE 1.6

So, I have two files:

File srcFile, dstFile;

When I want to move file srcFile to the place of dstFile:

boolean result = srcFile.renameTo(dstFile);

But there some errors can occur, and result will be false. In this case I want to ask user if he wants to repeat this operation. Which is the best way to do this? I would use a goto statement here, but Java doesn’t have it.

Currently, I am doing it in this way:

boolean retry = false;
do {
    if (!srcFile.renameTo(dstFile)) {
        // TODO: Error during file replacement
        Object[] retryOptions = { "Yes", "Retry" };
        replaceFileOption = JOptionPane.showOptionDialog(frame, "There was a error durring moving file" + srcFile.getPath() + ". Skip this file?", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    retryOptions, retryOptions[0]);
        if (replaceFileOption == 2) 
            retry = true;
    }
} while (retry);

Is there another way, which will not be using while() cycles?

  • 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-05-31T23:28:36+00:00Added an answer on May 31, 2026 at 11:28 pm

    When your goal was to avoid an extra var, do it this way

    while (!srcFile.renameTo(dstFile)) {
           Object[] retryOptions = { "Yes", "Retry" };
           if (2 != JOptionPane.showOptionDialog(frame, "There was a error durring moving file" + srcFile.getPath() + ". Skip this file?", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    retryOptions, retryOptions[0])) break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application and I want to move some of the tables from
I have a repository on my PC. Now I want to move some project
I want to move a file with Ruby. How do I do that?
I have some a UIView with several user created subviews. The user can move
I am using a trackBar1 to move between images I have on the hard
What are some good recommendations for managing SQL tables? I want to move away
I have a file that on each line is a string of some numbers
I have a directory (directory A) with 10,000 files in it. I want to
In my application i have a nib file (view A) containing some textFields. In
I'm doing some Wave file handling and have them read from disk into an

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.