import java.io.File;
import java.io.FileInputStream;
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.AclFileAttributeView;
import java.util.Arrays;
import java.util.List;

public class JI9044498 {

	public static void main(String[] args) throws IOException {
		String _FOLDER = "D:\\dev1\\data\\test"; 
		String _FILE = "D:\\dev1\\data\\test\\.md.truc"; 

		// 1. create dir 
		File folder = new File(_FOLDER); 
		boolean res = folder.mkdirs(); 
		System.out.println("Directory created? " + res); 

		// 2. touch acl of the folder 
		// note: if this is done AFTER the file creation, then no issue... 
		new JI9044498().touchAcl(folder.toPath()); 

		// 3. create file 
		Path fpath = Paths.get(_FILE); 
		List<String> lines = Arrays.asList("The first line", "The second line"); 
		Files.write(fpath, lines, Charset.forName("UTF-8")); 
		System.out.println("File written"); 

		// 4. read 
		System.out.println("can read folder = " + folder.canRead()); 
		System.out.println("can read file = " + fpath.toFile().canRead()); 

		try (FileInputStream is = new FileInputStream(fpath.toFile())) { 
			System.out.println("success opening file"); 
			is.close(); 
		} catch (IOException e) { 
			System.out.println("exception opening file : " + e.getMessage()); 
			throw e; 
		} 
	} 

	public void touchAcl(Path path) throws IOException 
	{ 
		System.out.println("touching Acl at: " + path.toString()); 
		AclFileAttributeView aclFileAttributes = java.nio.file.Files.getFileAttributeView(path, AclFileAttributeView.class); 
		aclFileAttributes.setAcl(aclFileAttributes.getAcl()); 
	} 

}
