Java examples for File Path IO:File Attribute
Define a User 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("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); } } }