package alx.p43_files;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.nio.file.attribute.UserPrincipal;
import java.util.Arrays;
import java.util.Set;

public class Tworzenie {

	public static void main(String[] args) {
		try {

			Path start = Paths.get("katalog");
			
			Path path = Paths.get("ala");
			if(! Files.exists(path)) {
				Files.createDirectory(path);
			}

			Path path2 = Paths.get("ola");
			Files.deleteIfExists(path2);
			Files.createFile(path2);

// dziala pod Linuxem			
//			Path path21 = Paths.get("uprawnienia");
//			Files.deleteIfExists(path21);
//			Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrw-r--");
//			Files.createFile(path21, PosixFilePermissions.asFileAttribute(perms));

			Path path3 = Files.createTempDirectory("temp");
			System.out.println(path3);

			byte[] buf = new byte[10];
			Arrays.fill(buf, (byte)68);
			
			Path path4 = Files.createTempFile("PLIK", ".tmp");
			System.out.println(path4);
			//Files.write(path4, buf);
			
			OutputStream stream = Files.newOutputStream(path4);
			stream.write(buf);
			stream.close();
			
			Path path5 = Files.createTempDirectory(start, "bbb");

			Path nowy = start.resolve("moj/nowy/katalog");
			
			Path path6 = Files.createDirectories(nowy);
			System.out.println(path6);

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