/** * 给文件以及父文件夹赋予权限 * @param path String类型的路径,要求是本地绝对路径 */ public static void givePrevilege(String path) { if (!PubFun.isEmpty(path)) { Setperms = new HashSet (); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.OWNER_EXECUTE); perms.add(PosixFilePermission.GROUP_READ); perms.add(PosixFilePermission.GROUP_EXECUTE); perms.add(PosixFilePermission.OTHERS_READ); perms.add(PosixFilePermission.OTHERS_EXECUTE); try { if (path.contains(".pdf")) { //给生成的pdf文件赋予权限 Path pathDest = Paths.get(path); Files.setPosixFilePermissions(pathDest, perms); mLogger.info(path + " 文件赋权成功"); } else { //给pdf文件的父目录赋予权限 Path pathDest = Paths.get(path); Files.setPosixFilePermissions(pathDest, perms); mLogger.info(path + " 文件夹赋权成功"); } //获取路径的文件对象,然后给父文件夹赋予权限 File file = new File(path); String parentPath = file.getParent(); givePrevilege(parentPath); } catch (IOException e) { mLogger.info(path + " 文件赋权失败"); e.printStackTrace(); } } }