Forum Discussion

Shivani3's avatar
Shivani3
Occasional Contributor
2 years ago

How to write string n file

How to add one string just below the existing line in a text file and also how we can save that file using javascript and test complete tool?

    • Shivani3's avatar
      Shivani3
      Occasional Contributor

      But with that it is only possible to skip the number of lines and the  it is replacing the existing text. But I don't want to replace that text I just want to create new line below the existing line then write on that line.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You can also use Scripting.FileSystemObject as shown below, which appends a string to the end of file.

    function AppendFile()
    {
        let FS = getActiveXObject("Scripting.FileSystemObject");
        let F = FS.OpenTextFile("C:\\Temp\\MyTest.txt", 8);
        F.WriteLine("Three");
        F.Close();
    }

     

    Again, you will have to create your own function, if you want to write a string to a specific location.