zoukankan      html  css  js  c++  java
  • DotNet,输出带Bom的文件

    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
    

      

  • 相关阅读:
    20165225《Java程序设计》第六周学习总结
    实验一 Java开发环境的熟悉
    20165225《Java程序设计》第五周学习总结
    移动web——bootstrap响应式工具
    移动web——bootstrap栅格系统
    移动web——bootstrap模板
    移动web——媒体查询
    移动web——轮播图
    移动web——touch事件应用
    移动web——touch事件介绍
  • 原文地址:https://www.cnblogs.com/pyblogs/p/3079583.html
Copyright © 2011-2022 走看看