This article describes in detail how to read and write javascript files, so that you can refer to the source code. Integrated the code for js File Reading and Writing on the Internet, but this function can only be executed in ie browser, and some computers need to set up ie.
The following code is written:
Var fso = new ActiveXObject ("Scripting. fileSystemObject "); // create an object var f = fso that can translate files into streams. createtextfile ("filename.txt", 2, "true"); // create a textSteam object. The first parameter is the absolute path of the file, the second parameter is permission (1 = read-only = ForReading, 2 = write only = ForWriting, 8 = append = ForAppending), and the third parameter is whether to allow the creation of f. write ("content"); // write content to a file. (Do not add a line break at the end of the data) f. writeLine ("content"); // Add a line break f. close () at the end of the data; // close the textSteam object
The following code is read:
Var fso = new ActiveXObject ("Scripting. fileSystemObject "); // create an object var f = fso that can translate files into streams. opentextfile ("filename.txt", 1, "true"); // create a textStream object with the same parameters as f. read (num); // read the specified number of characters in the file, such as f. read (2). The number of Chinese characters is also 1f. readLine (); // read an entire line, excluding the line break f. readAll (); // read the entire file content. close (); // close the textStream object
The above is the detailed content of javascript code sharing on file read/write instances. For more information, see other related articles in the first PHP community!