Adding new lines to text file in runtime. (javascript)

I want to create a method of recording what is happening in my drum game, like a midi file where every time a certain drum is played the time it has been played is recorded to a text file in real time and then read back. The problem I have is adding a new line without overwriting the entire file. In Response to the answers, I tried,

import System.IO; 
var sw = new StreamWriter("TestFile.txt"); 

function Start () {

function Update () {
    if (Input.GetButtonDown("keyOne")) {

    if (Input.GetButtonDown("keyTwo")) {

But nothing was written at all? And Erics answer, how do you use the append option? Sorry about this but i can't seem to find any IO documentation using JS. :'(

The first code sample is failing (unknown identifier "sw") because you have sw declared locally in the Start function instead of globally. When the Update function calls on sw it has no idea what it is because it's only been locally declared.

In your second code you declare sw once locally in the Start function and a second time locally in the Update function, so essentially it's two different variables. Try declaring it globally and see if that helps.

If you want StreamWriter to append instead of overwrite, then use the append option when creating the StreamWriter object.

Found it! Just put


The boolean is asking if you want to overwrite or append and it's set to false (overwrite) by default.