Java examples for File Path IO:Unix File
Creates a new file on a POSIX file system that has specific permissions.
import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; import java.util.Set; public class Main { public static void main(String[] args) { Path newfile = FileSystems.getDefault().getPath( "/home/folder1/folder2/2010/my.txt"); Set<PosixFilePermission> perms = PosixFilePermissions .fromString("rw-------"); FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions .asFileAttribute(perms);//w w w . ja v a 2s . c om try { Files.createFile(newfile, attr); } catch (IOException e) { System.err.println(e); } } }