/**
*
* @param dir
* 目标文件夹路径
* @return
*/
public static boolean isWritableDirectory(String path) {
Path dir = Paths.get(path);
if (null == dir)
throw new IllegalArgumentException("the argument 'dir' must not be null");
if (!Files.isDirectory(dir))
throw new IllegalArgumentException("the argument 'dir' must be a exist directory");
try {
Path tmpDir = Files.createTempDirectory(dir, null);
Files.delete(tmpDir);
} catch (IOException e) {
return false;
}
try {
Path tmpFile = Files.createTempFile(dir, null, null);
Files.delete(tmpFile);
} catch (IOException e) {
return false;
}
return true;
}
判断一个文件夹是否可写
最新推荐文章于 2022-03-15 13:28:41 发布