简体   繁体   中英

Inquiry about deleting symbolic links with Files.walkFileTree

From this java tutorial here :

Deleting a File or Directory

You can delete files, directories or links. With symbolic links, the link is deleted and not the target of the link. With directories, the directory must be empty, or the deletion fails.

On the other hand from here :

You need to decide whether you want symbolic links to be followed. If you are deleting files, for example, following symbolic links might not be advisable. If you are copying a file tree, you might want to allow it. By default, walkFileTree does not follow symbolic links.

They say, in the second quote, If you are deleting files, for example, following symbolic links might not be advisable However in the first quote it states clearly that: You can delete files, directories or links. With symbolic links, the link is deleted and not the target of the link. You can delete files, directories or links. With symbolic links, the link is deleted and not the target of the link.

If it's going to delete only the link and not the target, why would not be advisable following links when deleting while using Files.walkFileTree ?

Thanks in advance.

The issue with symbolic links is that you do not know where it is going to send you. So, if you delete recursively /etc/home/Rollerball/opt , maybe you forgot that there is a link to /bin that you forgot to think about.

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