简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM