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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:00:55+00:00 2026-05-22T13:00:55+00:00

I am working on a Java desktop application in which I need to implement

  • 0

I am working on a Java desktop application in which I need to implement recycle bin functionality. Currently:

  1. I copy a file using my desktop application to a folder named recycle bin, and then delete the original file.
  2. I store the destination path in a text file, where the file was deleted, just to restore the file to the original location.
  3. While restoring the file, I just move that file to the original location.

My problem is that when a file with the same name is deleted from different locations, all the files moved to the Recycle Bin folder created by me and the old file with the same names are overwritten.


How can I sort out this issue? Also, is there any other alternate way to get functionality similar to recycle bin?

  • 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-22T13:00:56+00:00Added an answer on May 22, 2026 at 1:00 pm

    When you delete a file:

    1. Generate a random number.
    2. Check if a file with that name already exists or not in your bin. If yes, go to 1.
    3. Copy the file to the bin directory, but use the random number as the file name.
    4. Store the original file name and the random number in your text file.
    5. Delete the original.

    (Note: this has issues if you have multiple applications/threads doing this at the same time.)

    All the information you need to “restore” the file is in the text file, and you’ve avoided the duplicate name problem.

    For more robustness against concurrent uses, and if you have Java 1.5 or greater, consider using a java.util.UUID rather than a “dumb” random number as the recycled file name. Can’t be guaranteed to be safe AFAIK, but it should be good enough in most circumstances (especially if there’s only one real user on the machine this is running).

    Lastly, make sure you’ve closed your output streams in steps 3 and 4 above before you delete, and that they didn’t throw any exception – otherwise you risk losing data. (Same thing when you restore: close the restored file stream before deleting the recycled one.)

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

Sidebar

Related Questions

I am working on a desktop application which uses JavaDB. I am using NetBeans
I'm currently working on a simple Java application that calculates and graphs the different
I'm working on a java web-application, trying to be xml-friendly and writing my jsp
I am developing a Java Desktop Application. In the GUI, I want that user
I am working on a Java Springframework project and using JUnit4 to test it.
I have been working on a java application that has a connection to a
I'm working with an older Java application that was written for Java 1.4, before
I am working on a support java project, which was fully developed years ago
I'm working in Java with XML and I'm wondering; what's the difference between an
I am working in Java on a fairly large project. My question is about

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.