新睿云

> 知识库 > ASP文件系统对象FSO

ASP文件系统对象FSO

作者/来源:新睿云小编 发布时间:2019-10-25

FileSystemObject.OpenTextFile(fname,mode,create,format)

FSO参数列表

以下代码创建一个文本文件(c:/ test.txt),然后将一些文本写入该文件:

<%

dim fs,fname

set fs=Server.CreateObject("Scripting.FileSystemObject")

set fname=fs.CreateTextFile("c:/test.txt",true) 'change to virtual path in shared hosting environment

fname.WriteLine("Hello World!")

fname.Close

set fname=nothing

set fs=nothing

%>

在共享托管环境中,将文件名从c:/ test.txt更改为您的虚拟路径;使用此代码作为文件路径,而不是server.mappath(“ / test.txt”)。

<%

Set fs=Server.CreateObject("Scripting.FileSystemObject")

If (fs.FileExists(server.mappath("/test.txt")))=true Then

Response.Write("File exists.")

Else

Response.Write("File does not exist.")

End If

set fs=nothing

%>

以下代码用于检查文件是否存在。

<%

Set fs=Server.CreateObject("Scripting.FileSystemObject")

Response.Write("The file extension of the file is: ")

Response.Write(fs.GetExtensionName(server.mappath("/test.txt")))

set fs=nothing

%>

以下代码用于获取文件扩展名。

<%

' create the fso object

set fso = Server.Createobject("Scripting.FileSystemObject")

path = server.mappath("/test.txt")

' open the file

set file = fso.opentextfile(path, 1) <-- For reading

do until file.AtEndOfStream

Response.write("Name: " & file.ReadLine & " ")

Response.write("Home Page: " & file.ReadLine & " ")

Response.write("Email: " & file.ReadLine & "<p>")

loop

' close and clean up

file.close

set file = nothing

set fso = nothing

%>

热门标签
new year
在线咨询
咨询热线 400-1515-720
投诉与建议
{{item.description}}

—您的烦恼我们已经收到—

我们会将处理结果发送至您的手机

请耐心等待