- Files.readAttributes()
Path path = Paths.get("/home/icer/note.txt"); PosixFileAttributes attr = null; try { attr = Files.readAttributes(path, PosixFileAttributes.class); } catch (Exception e) { e.printStackTrace(); } System.out.println("File owner: " + attr.owner().getName()); System.out.println("File group: " + attr.group().getName()); System.out.println("File permissions: " + attr.permissions().toString());
- Files.getFileAttributeView().readAttributes()
Path path = Paths.get("/home/icer/note.txt"); PosixFileAttributes attr = null; try { attr = Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS).readAttributes(); } catch (Exception e) { e.printStackTrace(); } System.out.println("File owner: " + attr.owner().getName()); System.out.println("
获取POSIX视图属性---POSIX
最新推荐文章于 2021-02-27 02:38:30 发布
本文介绍了如何使用Java NIO.2的Files类来读取Linux或Unix系统中文件的POSIX属性,包括文件所有者、组和权限。通过Files.readAttributes()和Files.getFileAttributeView().readAttributes()方法获取详细信息。
摘要由CSDN通过智能技术生成