Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: undo delete method

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    25
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default undo delete method

    So I have a method to delete a file from my file system but I wanted to write another method that could restore the previously deleted file. the only problem is I don't know how I would start writing it. My code for the delete the file is:

    public int unlink( String name )
        {
            for(int i = 0; i < C.DIR_ENTRIES; i++)
            {
                Directory de = readEntryDir(i);
     
                if (de.getName().equals(name))
                {
                    de.setName("");
                    writeEntryDir(i,de);
     
                    int curBlock = de.getStart();
                    int nextBlock = 0;
                    while(readEntryFAT(curBlock) != C.END)
                    {
                        nextBlock = readEntryFAT(curBlock);
                        writeEntryFAT(curBlock, C.FREE);
                        curBlock = nextBlock;
                    }
                    writeEntryFAT(curBlock, C.FREE);
                }
            }
            return C.OK;
        }

    Any help would be appreciated


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: undo delete method

    method that could restore the previously deleted file.
    How are you going to "delete" a file so that it can be restored? If you let the OS do it, the file could be gone.

    What classes are you using in the posted code? What packages does it import?

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    25
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: undo delete method

    Its an API file system, the method doesn't delete it just unlink the chain of blocks and can then be over written

    I want a method that would re-connect the block as long as it hasn't been over written
    Last edited by Trunk Monkeey; February 7th, 2012 at 10:34 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: undo delete method

    Its an API file system,
    What is an "API file system"?
    What options are in the API for that package's classes?

  5. #5
    Junior Member
    Join Date
    Nov 2010
    Posts
    25
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: undo delete method

    It is a big set of code we were given as part of our coursework. Its basically made up of Blocks which can linked together for the file system. I just couldn't think of how I could link up a previously link block.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: undo delete method

    How could anyone that does not have access to the data structure you are working with and the API you have for manipulating it, have any ideas on how to solve your problem?
    You need to study the data structure for the file system and classes and methods for working with it for ideas.

  7. #7
    Junior Member
    Join Date
    Nov 2010
    Posts
    25
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: undo delete method

    Well I was thinking that method would would be kind of similar to the deleting method only backwards and i'm assuming quite abit more coding

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: undo delete method

    I would think that undelete would restore the directory and chain of blocks containing the file's data to the way they were before the delete. If you can find all the pieces you could put them back together the way they were before the delete.

Similar Threads

  1. please need help ... for the delete method in array
    By yanikapausini:) in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 13th, 2012, 03:22 PM
  2. Disabling undo button in Word.
    By Silversurfer21 in forum Java Theory & Questions
    Replies: 0
    Last Post: September 5th, 2011, 09:03 AM
  3. Java Image Viewer undo function
    By mccaffrey in forum AWT / Java Swing
    Replies: 0
    Last Post: April 21st, 2011, 04:28 PM
  4. Can I delete one of these two?
    By ice in forum Java IDEs
    Replies: 2
    Last Post: November 14th, 2010, 04:02 AM
  5. [SOLVED] how do I undo an AlphaComposite?
    By gib65 in forum AWT / Java Swing
    Replies: 3
    Last Post: October 21st, 2010, 04:23 PM

Tags for this Thread