ASP: Create, open, write, and close files

Source: Internet
Author: User

Simply paste ASP to create, open, write, and close files. Post a complete post later

Create a file

Set objfso = server. Createobject ("scripting. FileSystemObject") 'defines the component
Objfso. createtextfile (server. mappath ("/newfolder/New. asp") 'create a file

Open the file:
1. opentextfile method of FileSystemObject object
Set objfso = server. Createobject ("scripting. FileSystemObject ")
Set objts = objfso. opentextfile (server. mappath ("a.txt"), 1, true) '1 indicates that after Read-Only 2 is cleared, the light is overwritten and calibrated at the end. If it is true, it is created if it does not exist. The default value is false.
2. openastextstream of the file object
Set objfso = server. Createobject ("scripting. FileSystemObject ")
Set objfile = objfso. GetFile (server. mappath ("a.txt "))
Set objts = objfile. openastextstream (1, true)

Read File Content
N = objts. Read (6)
N = objts. Readline
N = objts. readall

Write files
Objts. Write ("content ")
Objts. writeline ("new row and new content ")
Objts. writeblanklines ("3") 'write three blank rows

Close file
Objts. Close
Set objfso = nothing
Set objts = nothing

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.