Unity output text file or other file type

I have been struggling to get some old code to work in Unity 5 after upgrading. It seems some major changes have been put in place with I/O and I was wondering how to do this in modern Unity.

In the past I could use this:

 System.IO.File.WriteAllText(Application.dataPath + "/" + textName + fileExt, text);

Then I found I could almost use this:

string fileName = "Resources/mytext.txt";
            StreamWriter stream = File.CreateText(fileName);
            stream.WriteLine(SaveString);
            stream.Close();

But I can’t seem to get any write functions to work anymore. I’m using Unity 5.3.2p2 if that helps.

I’m getting errors that these write methods no longer work. What is used instead?

I apologize for solving my own problem, but this is the method I took.

string fileName = Application.dataPath + "/" + textName + fileExt;

            string textToAdd = "Example text in file";
            FileStream fs = null;
            try
            {
               
                fs = new FileStream(fileName, FileMode.CreateNew);
                using (StreamWriter writer = new StreamWriter(fs))
                {
                    writer.Write(textToAdd);
                }
            }
            finally
            {
                
                if (fs != null)
                    fs.Dispose();
            }

It works. I got most of it straight from here