欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp OpenTextFile文本讀取與寫(xiě)入實(shí)例代碼

 更新時(shí)間:2008年08月09日 20:54:37   投稿:mdxy-dxy  
打開(kāi)指定的文件并返回一個(gè) TextStream 對(duì)象,可以讀取、寫(xiě)入此對(duì)象或?qū)⑵渥芳拥轿募?

object.OpenTextFile(filename[, iomode[, create[, format]]]) 
參數(shù) 
object :必選項(xiàng)。應(yīng)為 FileSystemObject 對(duì)象的名稱(chēng)。 
filename :必選項(xiàng)。字符串表達(dá)式,指明要打開(kāi)的文件名稱(chēng)。 
iomode :可選項(xiàng)。輸入/輸出模式,是下列三個(gè)常數(shù)之一:ForReading,F(xiàn)orWriting,或 ForAppending。 
create :可選項(xiàng)。Boolean 值,指出當(dāng)指定的 filename 不存在時(shí)是否能夠創(chuàng)建新文件。允許創(chuàng)建新文件時(shí)為 True,否則為 False。默認(rèn)值為 False。 
format :可選項(xiàng)。三個(gè) Tristate 值之一,指出以何種格式打開(kāi)文件。若忽略此參數(shù),則文件以 ASCII 格式打開(kāi)。
設(shè)置 
iomode 參數(shù)可為下列設(shè)置之一: 
常數(shù)                 值                        描述 
ForReading        1         以只讀模式打開(kāi)文件。不能對(duì)此文件進(jìn)行寫(xiě)操作。 
ForWriting         2         以只寫(xiě)方式打開(kāi)文件。不能對(duì)此文件進(jìn)行讀操作。 
ForAppending    8         打開(kāi)文件并在文件末尾進(jìn)行寫(xiě)操作。 
format 參數(shù)可為下列設(shè)置之一: 
常數(shù)                              值              描述 
TristateUseDefault           -2        以系統(tǒng)默認(rèn)格式打開(kāi)文件。 
TristateTrue                   -1         以 Unicode 格式打開(kāi)文件。 
TristateFalse                    0         以 ASCII 格式打開(kāi)文件。 
說(shuō)明 
以下代碼舉例說(shuō)明如何使用 OpenTextFile 方法打開(kāi)寫(xiě)文件:

復(fù)制代碼 代碼如下:

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  

腳本之家寫(xiě)的一個(gè)判斷文件是否被更改過(guò)的代碼

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文件重新生成需要判斷是否更新過(guò)且文件不能小于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
'日志寫(xiě)入函數(shù)
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

相關(guān)文章

最新評(píng)論