How to delete a file with java (see mine code)-VBForums
Results 1 to 2 of 2

Thread: How to delete a file with java (see mine code)

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    5

    How to delete a file with java (see mine code)

    This program should delete cookedBooks.txt, but it doesnt. I created cookedBooks.txt in a folder. Can somebody push me in the right directions.

    Code:
    import java.io.File;
    import static java.lang.System.out;
    import java.util.Scanner;
    
    class DeleteEvidence {
    	
    	
    	
    	public static void main(String[] args) {
    
    		File evidence = new File("cookedBooks.txt");
    		Scanner keyboard = new Scanner(System.in);
    		char reply;
    
    		do	{
    			System.out.println("Delete Evidence? (Y/N) ");
    			reply = 
    			keyboard.findWithinHorizon(".",0).charAt(0);
    		} while (reply != 'y' && reply != 'n');
    
    		
    		if (reply == 'y') {
    			System.out.println("here we go");
    		evidence.delete();
    		System.out.println("Has been deleted");
    
    	}else{
    		System.out.println("Asking");
    
    	}
       }
    }

  2. #2
    Web developer Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    11,424

    Re: How to delete a file with java (see mine code)

    You need to place the file to be deleted in the main project folder outside the "src" folder.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    DON'T BUMP YOUR POSTS!!! Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.