ASP.net 写文件的函数(内容,路径,文件名) pcsky(原作)

'写文件的函数(内容,路径,文件名)
Public Sub FileWrite(ByVal Str As StringByVal myPath As StringByVal myFileName As String)
       
Dim path As String = HttpContext.Current.Server.MapPath(myPath)   '路径
       Dim temp As String = path & "" & myFileName                      '路径+文件名

       
' 删除原文件,如果存在
       If File.Exists(temp) Then
           File.Delete(temp)
       
End If

       
' 建立新文件
       Dim fs As FileStream = File.Create(temp)
       
Dim info As Byte() = Encoding.GetEncoding("gb2312").GetBytes(Str)

       
' 把内容添加到文件中
       fs.Write(info, 0, info.Length)
       fs.Close()
       
'Response.Write("<br>文件成功写入!")
End Sub
原文地址:https://www.cnblogs.com/pcsky/p/33884.html