java – file.canWrite(); file.canRead(); file.canExceute();虽然我的文件/目录没有访问权限,但总是返回true

前端之家收集整理的这篇文章主要介绍了java – file.canWrite(); file.canRead(); file.canExceute();虽然我的文件/目录没有访问权限,但总是返回true前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
需要检查我使用的文件/目录的权限
//filePath = path of file/directory access denied by user ( in windows )
 File file = new File(filePath);
 file.canWrite(); 
 file.canRead();
 file.canExecute();

所有三个都返回true但无法删除任何文件/目录

解决方法

你必须检查:
SecurityManager.checkDelete(filepath);

正如JavaDoc所述

猜你在找的Java相关文章