如何在ASP中打开文件

时间:2011-10-10 08:15:17

标签: file-io asp-classic

我不知道如何在ASP中打开文件。这是我的代码无效。

<%
    Dim vid_file
    vid_file = Request.ServerVariables("APPL_PHYSICAL_PATH")& "cannon\pay\vid.dat"
    Dim vkey_file
    vkey_file = Request.ServerVariables("APPL_PHYSICAL_PATH")& "cannon\pay\vkey.dat"

    dim fp1,f
    set fp1 = Server.CreateObject("Scripting.FileSystemObject")
    set f=fp1.OpenTextFile(Server.MapPath("vid_file"),8,true)
    f.WriteLine("This text will be added to the end of file")
    f.Close

    set f=Nothing
    set fp1=Nothing

    'Single Variable Declarations
    dim fp2,f2
    set fp2 = Server.CreateObject("Scripting.FileSystemObject")

    'fExists=FileSysObj.FileExists(vid_file)
    set f2=fp2.OpenTextFile(Server.MapPath("vkey_file"),8,true)
    'set TextStreamObj = fp2.OpenTextFile(vkey_file,1,true) 
    'TextStreamObj.WriteLine("This text will be added to the end of file")
    f2.WriteLine("This text will be added to the end of file")
    f2.Close

    set f2=Nothing
    set fp2=Nothing
%>

1 个答案:

答案 0 :(得分:1)

<%
    Dim vid_file
    vid_file = Request.ServerVariables("APPL_PHYSICAL_PATH")& "cannon\pay\vid.dat"
    Dim vkey_file
    vkey_file = Request.ServerVariables("APPL_PHYSICAL_PATH")& "cannon\pay\vkey.dat"

    dim fp1,f
    set fp1 = Server.CreateObject("Scripting.FileSystemObject")
     set f=fp1.OpenTextFile(vid_file,8,true)
    f.WriteLine("This text will be added to the end of file")
    f.Close
    set f=Nothing
    set fp1=Nothing
    'Single Variable Declarations
    dim fp2,f2
    set fp2 = Server.CreateObject("Scripting.FileSystemObject")
    'fExists=FileSysObj.FileExists(vid_file)
    set f2=fp2.OpenTextFile(vkey_file,8,true)
    'set TextStreamObj = fp2.OpenTextFile(vkey_file,1,true) 
    'TextStreamObj.WriteLine("This text will be added to the end of file")
    f2.WriteLine("This text will be added to the end of file")
    f2.Close
    set f2=Nothing
    set fp2=Nothing
    %>