System.IO.File' does not contain a definition for `AppendAllText' error in Unity3D?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 09:32:29

问题


I am very new to Unity3d and tried to open an existing project. While playing it shows the following error.

Assets/Scripts/DataAccess.cs(39,30): error CS0117: System.IO.File' does not contain a definition forAppendAllText'

I dont have any idea about how to solve this. I get stuck over here.

It would be appreciating if anyone solve this problem.

Thanks in advance...


回答1:


I ran into this, where no one else on my team could reproduce it.

We are targeting the iOS platform, and for some reason, my Build settings changed magically back to Web Player. Changing this BACK to iOS fixed the issue for me.

On Mac, I went to File ==> Build Settings...

The "Unity" icon was next to Web Player, so I switched it to iOS and hit the "Switch Platform" button. It reimported a bunch of stuff and, when it was done, the compiler error went away.




回答2:


You can try File.AppendText:

using(StreamWriter sw = File.AppendText(
          Application.persistentDataPath + "error.log"))
{
    sw.Write(e.ToString());
}

That may not be the best way to do this but it should work. I don't know if AppendAllText includes an implicit newline - doesn't appear to from the docs - but you might want .WriteLine instead.



来源:https://stackoverflow.com/questions/10121565/system-io-file-does-not-contain-a-definition-for-appendalltext-error-in-unity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!