Creating a file and writing into it? :p

Hello guys :O!

The title actually explains everything ^.^

thanks in advance

h4wkeye

1 Answer

1

You can use System.IO...

import System.IO;

Then you can use the different readers and writers depending on exactly what you want to do.

Look here for a reference…


edit(moved from comment)

#pragma strict
import System.IO;

public static class SimpleLogger extends ScriptableObject
{
    public function Start()
    {
        if (sw!=null) { return; }
        try {
            sw = new StreamWriter(Application.dataPath + "/log.txt");
        }
        catch (e : Exception) {
            //error handling
        }
    }
    public function LogMessage(message:String)
    {
        try {
            sw.WriteLine(message);
        }
        catch (e : Exception) {
            // error handling
        }
        finally {
            sw.Flush();
        }
    }
    public function Stop()
    {
        sw.Close();
    }
    private var sw : StreamWriter = null;
}