Java UserDefinedFileAttributeView set attribute

Description

Java UserDefinedFileAttributeView set attribute

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("Main.java");
      try {// w ww.  j a  v a 2 s.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();
      }
   }

}



PreviousNext

Related