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

  • SEARCH
  • Home
  • 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 8628611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:35:25+00:00 2026-06-12T08:35:25+00:00

When I try to save a file with the file name that already exists,

  • 0

When I try to save a file with the file name that already exists, I need to prompt the user to rename the file in order to save. What is the better way to prompt the user rename the File f the same File exists in the directory?I need to implement this via the same dialog box I use to save the file.

File exportFile = new File(FilePath + "\\"+ FileName);
boolean exists = exportFile.exists();  

if (!exists) {  

    System.out.println("File does not exists");  
    // TODO code here             
}
else{  

    System.out.println( "File exists.");
    // TODO code here                                       
}

The code is to be implemented in the //TODO part. How can I do this?

  • 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-12T08:35:27+00:00Added an answer on June 12, 2026 at 8:35 am

    while(exists) { \\Prompt the user to enter another name & change "exists" status correspondingly}

                while(exists) 
            {
             String temp=dis.readLine();
             exists = (FilePath + "\\"+ temp).exists();
             if(!exists) {exportFile = new File(FilePath + "\\"+ temp); break;}
    
              }  
    

    where dis is a DataInputStream object. Good luck.

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

Sidebar

Related Questions

I try to create a new file inside a JSP and try to save
I'm getting an error when I try to save a model that has a
I have an excel template that uses a macro to save the file, so
I have an Android app where I need to save a file. I create
I try to save my file status.txt to a specific directory call social. I
I need to save the barcode with timestamp and save that in a .csv
I have a code that creates file(s) in user-specified directory. User can point to
I try to save html content to the database, with ' or it auto
When I try to save images to a directory, it's not saving to my
When I try and save something to my list in SharePoint I get the

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.