Is there something wrong with this code:
using UnityEngine;
using System.Collections;
using System;
using System.IO;
public class Files : MonoBehaviour {
public string filename="";
public string[] args;
void Update() {
if(Input.GetKeyDown("t")) {
Read(args);
}
}
void Read(string[] strs) {
StreamWriter w = File.AppendText(Application.persistentDataPath+"/"+filename+".txt");
foreach(string s in strs) {
Log(s, w);
}
w.Close();
StreamReader r = File.OpenText(Application.persistentDataPath+"/"+filename+".txt");
DumpLog(r);
r.Close();
}
void Log(string logMessage, TextWriter w) {
w.Write("\r\n"+logMessage);
w.Flush();
}
void DumpLog(StreamReader r) {
string line = r.ReadLine();
while(line != null) {
Debug.Log(line);
}
r.Close();
}
}
because for some reason, everytime I hit “t”, Unity freezes, but the file is created and all of the info is in the file… is there something I’m missing? a Close(); somewhere?