Skip to main content
Search our knowledge base

How do I read and write data from a text file?

Comments

6 comments

  • Nishal John

    This was exactly what I was looking for to create a Log System. Thanks!

    0
  • Ben

    Does system.io streamwritting work on all platforms, mobile & webplayer for example?

    4
  • Fran D.

    The [MenuItem("Tools/XXXX file")] part is misleading because is not needed to solve the problem and what is worse it's use (which is not straightforward) it's not explained: not even a screenshot nor anything

     

    -1
  • Andrew Watson

    If you are developing for Hololens or mixed reality, you'll need to pass a stream in. This works fine for working in the editor, but when you try to build a solution under Universal Windows Platform, you'll get an error. Here's what I did:

     

    try
    {
    using (StreamWriter sw = new StreamWriter(new FileStream("Assets/" + FileName + ".txt", FileMode.OpenOrCreate, FileAccess.Write)))
    {

    string line = "";

    //logic logic logic


    sw.Write(line);

    }
    }
    catch (Exception e)
    {

    }

     

     

    3
  • Contractor Nation

    perfect! I needed TextAsset.text for Quest to read from Assets/myFile.html and used StreamWriter for Quest to write to /sdcard/Android/data/myPkgId/files, and a PC player can access the sdcard via adb

    0
  • AwsApps

    is there a way to format the code?

    0

Please sign in to leave a comment.