Define a User Attribute - Java File Path IO

Java examples for File Path IO:File Attribute

Description

Define a User Attribute

Demo Code

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.UserDefinedFileAttributeView;

public class Main {
  public static void main(String[] args) {
    Path path = Paths.get("C:/folder1/folder2/folder4", "test.txt");
    UserDefinedFileAttributeView udfav = Files.getFileAttributeView(path,
        UserDefinedFileAttributeView.class);
    try {/*w w  w  .ja va 2  s.  c o  m*/
      int written = udfav.write("file.description", Charset.defaultCharset()
          .encode("This file contains private information!"));
    } catch (IOException e) {
      System.err.println(e);
    }

  }
}

Result


Related Tutorials