List of usage examples for java.nio.file Files getAttribute
public static Object getAttribute(Path path, String attribute, LinkOption... options) throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt"); //extract a single attribute with getAttribute try {//from w w w. ja v a2s . c o m long size = (Long) Files.getAttribute(path, "basic:size", java.nio.file.LinkOption.NOFOLLOW_LINKS); System.out.println("Size: " + size); } catch (IOException e) { System.err.println(e); } }
From source file:com.spectralogic.ds3client.metadata.PosixMetadataRestore_Test.java
@Test public void restoreUserAndOwner() throws IOException { final int uid = (int) Files.getAttribute(file.toPath(), "unix:uid", NOFOLLOW_LINKS); final int gid = (int) Files.getAttribute(file.toPath(), "unix:gid", NOFOLLOW_LINKS); final BasicHeader basicHeader[] = new BasicHeader[2]; basicHeader[0] = new BasicHeader(MetadataKeyConstants.METADATA_PREFIX + MetadataKeyConstants.KEY_UID, String.valueOf(uid)); basicHeader[1] = new BasicHeader(MetadataKeyConstants.METADATA_PREFIX + MetadataKeyConstants.KEY_GID, String.valueOf(gid)); final Metadata metadata = genMetadata(basicHeader); final PosixMetadataRestore posixMetadataRestore = new PosixMetadataRestore(metadata, file.getPath(), MetaDataUtil.getOS());//ww w .j a va2s .c om posixMetadataRestore.restoreUserAndOwner(); Assert.assertEquals(String.valueOf((int) Files.getAttribute(file.toPath(), "unix:uid", NOFOLLOW_LINKS)), basicHeader[0].getValue()); Assert.assertEquals(String.valueOf((int) Files.getAttribute(file.toPath(), "unix:gid", NOFOLLOW_LINKS)), basicHeader[1].getValue()); }
From source file:com.att.aro.core.fileio.impl.FileManagerImpl.java
public long getCreatedTime(String filePath) throws IOException { File file = new File(filePath); FileTime fileTime = (FileTime) Files.getAttribute(file.toPath(), "creationTime", LinkOption.NOFOLLOW_LINKS); if (fileTime != null) { return fileTime.to(TimeUnit.SECONDS); }/*from w ww. ja v a 2 s . c o m*/ return 0; }