Game crashing when writing to file using streamwriter.

Hello!

I have a small game that works perfectly in the Unity game view. The player searchers for an object and once the object is found the game records the results of the search to a text file. However, in the build, the game crashes once it reaches this point in the program.

I am using the stream writer function to record data.
My code is as follows:

At the top I have:

   using UnityEngine;
    using System.Collections;
    using System.Diagnostics;
    using System.Threading;

Then I have a subroutine that handles data writing:

public void dataRecord () {
    		
    		        		RTWatch.Stop ();
    		using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Test\" + subjNumber + ".txt", true)) {
    			file.WriteLine (subjNumber+ "	" + stepRatio + "	" + trial + "	" + position + "	" + corrTarget + "	" + resp + "	" + corr + "	" + RTWatch.ElapsedMilliseconds);
    		}
    		RTWatch.Reset ();
    }

Any thoughts on why this may be happening? I’m especially confused since it works correctly in the game view within unity.

Thank you!

Well, the most obvious answer is that the file path you’re providing is not valid for the platform you’re building for.