DotNet,输出带Bom的文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | 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 |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· dotnet 源代码生成器分析器入门
· 官方的 MCP C# SDK:csharp-sdk
· 一款 .NET 开源、功能强大的远程连接管理工具,支持 RDP、VNC、SSH 等多种主流协议!
· 一步一步教你部署ktransformers,大内存单显卡用上Deepseek-R1
· 一次Java后端服务间歇性响应慢的问题排查记录