Create Text file and open - write on it after button click

Hello there. My code is like that;

	void Start () {
		StreamWriter sr = File.CreateText(FILE_NAME);
		sr.Close();
	}
	
	void Update () {
		if (Input.GetMouseButtonDown (0) && EventSystem.current.currentSelectedGameObject == button1) 
		{
			StreamWriter sr = File.OpenWrite (FILE_NAME);
			sr.WriteLine ("You clicked on first button.");
			sr.Close();
		}
        else if (Input.GetMouseButtonDown (0) && EventSystem.current.currentSelectedGameObject == button2) 
		{
			StreamWriter sr = File.OpenWrite (FILE_NAME);
			sr.WriteLine ("You clicked on second button.");
			sr.Close();
		}
 }

My aim is basic actually. When I clicked on button it should be written on a Text file. I think I have a problem about opening and closing of text file. Because I got ‘Cannot implicitly convert type "System.IO.FileStream’ to ‘System.IO.StreamWriter’ " error.

What should I do now? Thanks in advance.

Maybe this can help you.

var file = File.Open("File_Name", FileMode.OpenOrCreate, FileAccess.ReadWrite);
var writer = new StreamWriter(file);
var reader = new StreamReader(file);

Or the simple way:

var textFile = File.ReadAllText("C:/Filename.txt");
File.WriteAllText("C:/Filename.txt", textFile + "Hello");