Imports Microsoft.Win32
Imports System.IO
Imports System.Text
Namespace 朋友博客集
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
Public Class OutputFile_Disk
''' <summary>
'''
''' </summary>
''' <param name="filePath"></param>
''' <param name="fileName"></param>
''' <param name="theCode"></param>
''' <param name="extName"></param>
''' <param name="WithUTF8BOM">输出的文件是否带有UTF8BOM</param>
''' <remarks></remarks>
Private Shared Sub FileOutput_Ext(ByRef filePath As String, ByRef fileName As String, ByRef theCode As String, ByVal extName As String, Optional ByVal WithUTF8BOM As Boolean = False)
If Not Directory.Exists(filePath) Then
Directory.CreateDirectory(filePath)
End If
Dim Path As String = filePath & fileName & extName
Dim Encoding_UTF8 As Encoding = New UTF8Encoding(False, True) '默认无BOM
If WithUTF8BOM Then Encoding_UTF8 = New UTF8Encoding(True, True)
' Create a file to write to.
Using fs As FileStream = New FileStream(Path, FileMode.Create) '创建或覆盖
Using sw As StreamWriter = New StreamWriter(fs, Encoding_UTF8)
sw.Write(theCode)
sw.Flush()
End Using
End Using
End Sub
''' <summary>
'''
''' </summary>
''' <param name="filePath"></param>
''' <param name="fileName"></param>
''' <param name="theCode"></param>
''' <remarks></remarks>
Public Shared Sub FileOutput_VB(ByRef filePath As String, ByRef fileName As String, ByRef theCode As String)
Dim extName As String = ".vb"
FileOutput_Ext(filePath, fileName, theCode, extName)
End Sub
Public Shared Sub FileOutput_ASPX(ByRef filePath As String, ByRef fileName As String, ByRef theCode As String)
Dim extName As String = ".aspx"
FileOutput_Ext(filePath, fileName, theCode, extName, True)
End Sub
End Class
End Namespace