This is working fine but i realise that the file will be overwrite every time a new game is play which is not i want. I want to maintain the data. Instead of overwrite the data, i want to add on to the data. Any thing bother me is regarding, how we know this file is belong to which players. Is it any possible way i can solve this issues? Like this data in this file is the record play by may… Please help!!! :((
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;
print(gameControl.previousWord1);
}
// Update is called once per frame
void Update ()
{
//string messageToAccess = gameControl.previousWord1;
path = Application.dataPath + fileName;
using(FileStream fs = File.Create(path))
{
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.previousWord1[j]);
}
AddText(fs, " " + gameControl.wrongMatch + "
");
}
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);
}
}