asp OpenTextFile文本读取与写入实例代码_应用技巧

object.OpenTextFile(filename[, iomode[, create[, format]]]) 
参数 
object :必选项。应为 FileSystemObject 对象的名称。 
filename :必选项。字符串表达式,指明要打开的文件名称。 
iomode :可选项。输入/输出模式,是下列三个常数之一:ForReading,ForWriting,或 ForAppending。 
create :可选项。Boolean 值,指出当指定的 filename 不存在时是否能够创建新文件。允许创建新文件时为 True,否则为 False。默认值为 False。 
format :可选项。三个 Tristate 值之一,指出以何种格式打开文件。若忽略此参数,则文件以 ASCII 格式打开。
设置 
iomode 参数可为下列设置之一: 
常数                 值                        描述 
ForReading        1         以只读模式打开文件。不能对此文件进行写操作。 
ForWriting         2         以只写方式打开文件。不能对此文件进行读操作。 
ForAppending    8         打开文件并在文件末尾进行写操作。 
format 参数可为下列设置之一: 
常数                              值              描述 
TristateUseDefault           -2        以系统默认格式打开文件。 
TristateTrue                   -1         以 Unicode 格式打开文件。 
TristateFalse                    0         以 ASCII 格式打开文件。 
说明 
以下代码举例说明如何使用 OpenTextFile 方法打开写文件:

复制代码 代码如下:

Sub OpenTextFileTest    
  Const ForReading = 1, ForWriting = 2, ForAppending = 8    
  Dim fso, f    
  Set fso = CreateObject("Scripting.FileSystemObject")    
  Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)    
  f.Write "嗨,你好!"   
  f.Close    
End Sub  

写的一个判断文件是否被更改过的代码

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
set fn2=fso.GetFile("E:\webroot\jb51\index2.htm")
flsize2=fn2.size
fldate2=fn2.datelastmodified
set fn=fso.GetFile("E:\webroot\jb51\index.htm")
flsize1=fn.size
fldate1=fn.datelastmodified
If fso.FileExists("E:\webroot\jb51\index2.htm") and flsize2>50000 and fldate2>fldate1 Then
'判断文件的大小,如果html文件重新生成需要判断是否更新过且文件不能小于50K
fso.getfile("E:\webroot\jb51\index2.htm").copy("E:\webroot\jb51\index.htm")
if err.number=0 then WriteHistory "成功"&now()&".........","log.txt"
end if
'日志写入函数
Sub WriteHistory(hisChars, path)
 Const ForReading = 1, ForAppending = 8
 Dim fso, f
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set f = fso.OpenTextFile(path, ForAppending, True)
 f.WriteLine hisChars
 f.Close
End Sub

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索asp
, 文本
OpenTextFile
opentext、opentextfile 参数、opentext 中国、opentextfile、fso.opentextfile,以便于您获取更多的相关知识。

时间: 2024-07-31 01:31:02

asp OpenTextFile文本读取与写入实例代码_应用技巧的相关文章

asp.net中文件下载功能的实例代码_实用技巧

复制代码 代码如下: //TransmitFile实现下载protected void Button1_Click(object sender, EventArgs e){ Response.ContentType = "application/x-zip-compressed";Response.AddHeader("Content-Disposition", "attachment;filename=z.zip");string filena

asp.net StreamReader 创建文件的实例代码_实用技巧

复制代码 代码如下: using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;us

asp.net 获取图片高度和宽度实例代码_实用技巧

复制代码 代码如下: string path = Server.MapPath("img/1.gif"); System.Drawing.Image image = System.Drawing.Image.FromFile(path); Response.Write("宽:" + image.Width + "<br />"); Response.Write("高:" + image.Height );

Asp.Net获取网站截图的实例代码_实用技巧

复制代码 代码如下: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication1{    public partial class Form1 : Form    {    

asp.net repeater手写分页实例代码_实用技巧

复制代码 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BLL; using Model; using System.Data.SqlClient; using System.Data; public partial class Test_Re

Asp.net中安全退出时清空Session或Cookie的实例代码_实用技巧

概览: 网站中点击退出,如果仅仅是重定向到登录/出页面,此时在浏览器地址栏中输入登录后的某个页面地址如主页,你会发现不用登录就能访问.这种所谓的退出并不是安全的. 那么怎样做到安全退出呢? 那就是点击退出后清空相应的Session或Cookie. 清空Session的代码: Session.Clear(); Session.Abandon(); 清除Cookie的正确代码(假设Cookie名称为UserInfo): if (Request.Cookies["UserInfo"] !=

ASP.NET 多附件上传实现代码_实用技巧

但基本前提都是事先通过js脚本来动态创建DOM,然后上传的时候在服务端做一下处理,有点类似于163的邮件系统.文件上传需要通过页面的POST方法进行提交,这个我在一次MOSS开发中iFrame表单提交的古怪问题解决一问中已经阐述过,其中包括了如何使用页面隐藏的iFrame来提交表单从而避免整个页面提交到服务器而导致页面的刷新.多附件上传的原理与之类似,只不过需要事先通过脚本在页面上动态创建多个input type='file'的标签,当然,如果要想功能更加完美,你可能还需要通过脚本动态添加一些按

ASP所有的Session变量获取实现代码_应用技巧

复制代码 代码如下: Dim strName, iLoop For Each strName in Session.Contents Response.Write strName & " - " & Session.Contents(strName)& "[BR]" Next 一般情况下,上面的代码可以工作得很好.但当Session变量是一个对象或者数组时,打印的结果就不正确了. 这样我们修改代码如下: 复制代码 代码如下: '首先看看有多少

asp下使用数组存放数据的代码_应用技巧

asp用客户端数组存放数据,这种应用我已经见过很多.但最近在研究几套流量交换联盟系统时,这种技术才引起了我的注意. 下面我讲讲如何运用,先给出个没有结合ASP,就单纯适用javascript的例子. 1.js 复制代码 代码如下: var a = new Array();  var temp = "<table>";  a[0] = new Array(1,"阿会楠","男");   a[1] = new Array(2,"