获取项目相对路径
String serverPath = Thread.currentThread().getContextClassLoader().getResource("").toString();
serverPath = serverPath.replace(’/’, ‘\’);
serverPath = serverPath.replace(“file:”, “”);
serverPath = serverPath.replace(“classes\”, “”);
serverPath = serverPath.replace(“target\”, “”);
serverPath = serverPath + “upload”;
维护文件权限:
- 设置文件权限
- @param dirFile
- @throws IOException
*/
private static void changeFolderPermission(File dirFile) throws IOException {
Set perms = new HashSet();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.OTHERS_READ);
try {
Path path = Paths.get(dirFile.getAbsolutePath());
Files.setPosixFilePermissions(path, perms);
} catch (Exception e) {
e.printStackTrace();
}
}