Search Unity

How to write on a text file through javascript ....

Discussion in 'Scripting' started by Dinesh Balu, Apr 7, 2011.

  1. Dinesh Balu

    Dinesh Balu

    Joined:
    Mar 10, 2011
    Posts:
    255
    I'm using this method to read a text file through javascript..

    Code (csharp):
    1.  
    2.    var sr = new StreamReader(Application.dataPath + "/" + fileName);
    3.     var fileContents = sr.ReadToEnd();
    4.     sr.Close();
    5.  
    Now... How to write on a text file with or without appending through the javascript....?
     
  2. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    File.WriteAllText(path, text)
     
  3. Dinesh Balu

    Dinesh Balu

    Joined:
    Mar 10, 2011
    Posts:
    255
    Thanks Mitch.

    Here the File.WriteAllText() is the function and the argument path denotes the path of the textfile and text denotes the string variable holding the content to be written.... right?

    Now does this funtion replaces the contents of file with new content OR it just appends the New content with the existing content?
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you can lookup System.IO.File.WriteAllText on MSDN to find out what it does
     
  5. Dinesh Balu

    Dinesh Balu

    Joined:
    Mar 10, 2011
    Posts:
    255
    Thanks dreamora... :)