user3450754
user3450754

Reputation: 115

Deleting a binary Java Files

I am trying to find a way to delete the binary files that I have created. I can do it by going to the folder, but I want to do it through the program.

Such as the program asks --> Enter the name of the file you want to delete: for example: Bob (processing...) binary file has been deleted. this is what I want my method to do. However I do not know how to do it, Is there a method to delete a binary file or do I have to write my own code to delete a binary file?

Upvotes: 0

Views: 1824

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201409

You could use File.delete(), from the linked Javadoc,

Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted.

So I believe you might use something like

new File("c:/some/folder/binary.file").delete();

Alternatively, you can schedule things to be deleted on exit with File.deleteOnExit() which

Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.

Upvotes: 2

Related Questions