读文件
private void ReadFile(string country){
StreamReader sr = null;
try {
sr = File.OpenText (Application.persistentDataPath + "//" + "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+"//"+"FileName"+".txt");
StreamWriter sw;
FileInfo fi=new FileInfo(Application.persistentDataPath+"//"+"FileName"+".txt");
if(!fi.Exists) {
sw = fi.CreateText();
} else{
sw = fi.AppendText();
}
sw.Write ("");
sw.Flush();
sw.Close();
}
网友评论