沙盒路径
沙盒路径: Application.dataPath +”xxx”;
写入操作 StreamWrite –sw.Write() 写入文档
读入操作 StreamReader – sr.ReadToEnd() 读入文档
创建文件,写内容
public void CreateAndWrite(){
string path = Application.dataPath + "/Resources/Q.txt";
FileStream fs = null;
if (!File.Exists (path)) {
fs = File.Create (path);
} else {
fs = File.Open (path, FileMode.Open);
}
StreamWriter sw = new StreamWriter (fs);
string content = "1001|第一件衣服|IconA.png";
sw.Write (content);
sw.Flush ();
sw.Close ();
fs.Close ();
Debug.Log (path);
}
读文件内容
public void ReadText(){
string path = Application.dataPath + "/Resources/Q.txt";
FileStream fs = null;
if (!File.Exists (path)) {
return;
} else {
fs = File.Open (path, FileMode.Open);
}
StreamReader sr = new StreamReader (fs);
string str = sr.ReadToEnd ();
sr.Close ();
fs.Close ();
Debug.Log (str);
}