用asp写一个程序 1、可以在服务器中生成一个TXT文件 2、可以像该TXT文件中写入数据,覆盖掉其中所有的数据

界面可以不用管,我比较重功能,成功了分数一定给你。
2025-02-28 23:27:41
推荐回答(4个)
回答1:

我给你一段,我的计数器的源码:我想原理就是你要的功能了,我的计数器是先检查有无文件count.txt,如无则新建并赋值为0,如有则读取数据,并加1;
<%
fileName=Server.MapPath("count.txt")
Set fs=Server.CreateObject("Scripting.FileSystemObject")

'初始化
Function Init()

'检查文件是否存在,不存在则创建,并写入0
If Not fs.FileExists(fileName) Then
fs.CreateTextFile fileName,True,True
Set txt=fs.OpenTextFile(fileName,2,True)
txt.Write 0
txt.close()
Set txt=Nothing
End If

'缓存为空,则读取文本数据
Set txt=fs.OpenTextFile(fileName,1,1)
If txt.AtEndOfStream Then
Application("Counter")=0 '如果文件中没有数据,则初始化Application("Counter")的值(为了容错)
Else
Application("Counter")=txt.ReadLine
End If
txt.close()
Set txt=Nothing
if session("ip_sx")="" then
Application.Lock '利用Application特性防止并发写入
Application("Counter") = Application("Counter") + 1
SaveNum(Application("Counter")) '写入新数据
Application.UnLock
session("ip_sx")="true"
end if
End Function
%>

回答2:

用FSO对象吧,一般ASP进行文件操作都是用FOS,网上也有很多类似的实例。

回答3:

<%
Dim objFso,objFile
Dim strPath
strPath = "C:\KingsNet\"
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
If Not objFso.FolderExists(strPath) Then objFso.CreateFolder(strPath)
Set objFile = objFso.CreateTextFile(strPath & "1.TXT", True)
objFile.Write strPath
objFile.Close
Set objFile = Nothing
Set objFso = Nothing
%>

回答4:

你给的概念很模糊,你重什么功能呢,没具体到什么的程序哦