我正在使用下面的代码,但它不起作用。canWrite()
即使更改目录的写入权限,该方法也不起作用。
File file = new File(fc.getSelectedFile().getAbsolutePath());
// fc is a FileChooser object
if(f.canWrite())
{
// write access
}
else
{
// no write access
}
我也试过:
try
{
AccessController.checkPermission(new FilePermission("/tmp/*", "read,write"));
System.out.println("Good");
// Has permission
}
catch (SecurityException e)
{
// Does not have permission
System.out.println("Bad");
}