import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class TestJavaNIO {
    public static void main(String[] args) {
        Path path = Paths.get("Colors.txt");
        try {
            BufferedReader reader = Files.newBufferedReader(path);
            String record = null;
            while ((record = reader.readLine()) != null) {
                System.out.println(record);
            }
            reader.close();
        }
        catch (IOException ex) {
            System.out.println(ex.getMessage());
        }

        try {
            BufferedWriter writer =  Files.newBufferedWriter(path);
            writer.write("Red\n");
            writer.write("Green\n");
            writer.write("Blue\n");
            writer.close();
        }
        catch (IOException ex) {
            System.out.println(ex.getMessage());
        }

    }
}