讀文件
private void ReadFile(string country){
StreamReader sr = null;
try {
sr = File.OpenText (Application.persistentDataPath + "http://" + "FileName" + country + ".txt");
AllData = sr.ReadToEnd ();
//dosomething
} catch (Exception e) {
Debug.Log("error:"+e.Message);
}
sr.Close ();
sr.Dispose ();
}
寫文件
public void WriteToFile(){
File.Delete (Application.persistentDataPath+"http://"+"FileName"+".txt");
StreamWriter sw;
FileInfo fi=new FileInfo(Application.persistentDataPath+"http://"+"FileName"+".txt");
if(!fi.Exists)? ? ? ? ? {
sw = fi.CreateText();
} else{
sw = fi.AppendText();
}
sw.Write ("");
sw.Flush();
sw.Close();
}