Search code examples
javascriptjscript-10

Jscript ReadLine() related


Can any one please tell me that we use ReadLine() to read a particular line from a file (.txt). Now I want to read the total content of the file (not only the first line). For that what method I need to use. I googled a lot but I cant get the solution.

My Code is given below:

    var ForReading = 1;
    var TristateUseDefault = -2;
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var newFile = fso.OpenTextFile(sFileName, ForReading, true, TristateUseDefault);
    var importTXT = newFile.ReadLine();

This is returning the first line of the .txt file by importTXT variable. Now I want to get the total file content in importTXT.

Any suggestion will be very much helpful for me.


Solution

  • You use the ReadAll method:

    var importTXT = newFile.ReadAll();
    

    (Don't forget to close the stream when you are done with it.)