The code below is only creating one file and overwrite the data after each game is started. What i want to do is to create new file every time a new game is play. How can i go about doing it??
using UnityEngine;
using System.Collections;
using System;
using System.Text;
using System.IO;
public class Monitor : MonoBehaviour {
String path;
String fileName;
String playerName;
int id =1;
// Use this for initialization
void Start ()
{
fileName = "/Monitoring.txt";
playerName = playerControl.playerName;
path = Application.dataPath + fileName;
print(gameControl.previousWord1);
}
// Update is called once per frame
void Update ()
{
//string messageToAccess = gameControl.previousWord1;
using(FileStream fs = File.Create(path))
//using(FileStream fs = new FileStream(path, FileMode.Append, FileAccess.ReadWrite))
{
AddText(fs, "PlayerName: " + playerName);
AddText(fs, "
================================");
AddText(fs, "
" + id);
for(int j = 0; j < gameControl.radical00Store.length; j++)
{
AddText(fs, " " + gameControl.radical00Store[j]);
AddText(fs, " " + gameControl.radical0Store[j]);
AddText(fs, " " + gameControl.wrongStore[j] + "
");
}
}
id++;
//Open the stream and read it back.
using (FileStream fs = File.OpenRead(path))
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
}
}
private static void AddText(FileStream fs, string value)
{
byte[] info = new UTF8Encoding(true).GetBytes(value);
fs.Write(info, 0, info.Length);
}
}