0

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.

4

2 に答える 2

1

ここ: ReadAll (msdn)

与えられた例が非常に貧弱であることがわかりました-たとえば、ファイルを閉じなかったので、これをmsdnページに追加しました:

function ReadAllTextFile(filename)
{
    var ForReading = 1;
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // Open the file for input.
    var f = fso.OpenTextFile(filename, ForReading);

    // Read from the file.
    var text = (f.AtEndOfStream)?"":f.ReadAll(); // this is where it is read
    f.Close();
    return text;
}
var importTXT = ReadAllTextFile(sFileName);
于 2011-09-15T05:46:37.407 に答える
1

ReadAllメソッドを使用します。

var importTXT = newFile.ReadAll();

(完了したら、ストリームを閉じることを忘れないでください。)

于 2011-09-15T05:49:40.447 に答える