回复 4楼 张六先生
1.VB6写入带BOM的utf-8文本文件
工程--引用--勾选Microsoft ActiveX Data Object 2.5 Library或更高的版本
Private Sub Form_Load()
Dim adostream As New ADODB.Stream
With adostream
.Type = adTypeText
.Mode = adModeReadWrite
.Charset = "utf-8"
.Open
.Position = 0
.WriteText "测试文字369"
.SaveToFile "D:\test.txt", adSaveCreateOverWrite
.Close
End With
Set adostream = Nothing
End Sub
2.VB6写入无BOM的utf-8文本文件
工程--引用--勾选Microsoft ActiveX Data Object 2.5 Library或更高的版本
Private Sub Form_Load()
Dim WriteStream As Object, BinSt As Object
Dim name As String
Dim nameto As String
Set WriteStream = CreateObject("ADODB.Stream")
Set BinSt = CreateObject("ADODB.Stream")
nameto = "D:\test.txt"
With WriteStream
.Open
.Charset = "UTF-8"
.Type = 2
'adTypeText
(文本)
.WriteText "测试文字369"
.Position = 3
End With
With BinSt
.Open
.Type = 1
'(字节)
End With
WriteStream.CopyTo BinSt '数据复制
With BinSt
.SaveToFile nameto, 2
'保存文件
.Close
End With
WriteStream.Close
Set WriteStream = Nothing
Set BinSt = Nothing
End Sub
[此贴子已经被作者于2022-10-18 18:17编辑过]