Javascript code sharing for file read/write instances

Source: Internet
Author: User
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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.