Maintaining user-defined file attributes using the UserDefinedFileAttributeView - Java File Path IO

Java examples for File Path IO:File Attribute

Description

Maintaining user-defined file attributes using the UserDefinedFileAttributeView

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:/home/docs/users.txt");
    try {//from w  w  w .j a v a 2s .  c o  m
      UserDefinedFileAttributeView view = Files.getFileAttributeView(path,
          UserDefinedFileAttributeView.class);
      view.write("publishable", Charset.defaultCharset().encode("true"));
      System.out.println("Publishable set");

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Related Tutorials