有关vb.net操作文档出现乱码问题
ImportsSystem.IOPublicClassForm1PrivateSubButton1_Click(ByValsenderAsSystem.Object,By...
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim intLine As Integer = 1
Using sw As New StreamWriter("H:\编程资料\1.txt")
Using sr As New StreamReader("H:\编程资料\2.txt")
Do
Dim strRead As String = sr.ReadLine()
If strRead Is Nothing Then Exit Do
If intLine = 2 Then
sw.WriteLine("修改的内容")
Else
sw.WriteLine(strRead)
End If
intLine += 1
Loop
sr.Close()
End Using
sw.Close()
End Using
End Sub
End Class
以上是代码,如果操作的是中文的话,就会出现乱码,而且平时我操作文档或者直接拖曳文档到textbox时,只要有中文就会出现乱码 展开
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim intLine As Integer = 1
Using sw As New StreamWriter("H:\编程资料\1.txt")
Using sr As New StreamReader("H:\编程资料\2.txt")
Do
Dim strRead As String = sr.ReadLine()
If strRead Is Nothing Then Exit Do
If intLine = 2 Then
sw.WriteLine("修改的内容")
Else
sw.WriteLine(strRead)
End If
intLine += 1
Loop
sr.Close()
End Using
sw.Close()
End Using
End Sub
End Class
以上是代码,如果操作的是中文的话,就会出现乱码,而且平时我操作文档或者直接拖曳文档到textbox时,只要有中文就会出现乱码 展开
1个回答
展开全部
在使用streamReader和streamWriter的时候使用编码参数。
比如:dim sw As New StreamRriter("H:\编程资料\1.txt",System.Text.Encoding.Default)
dim sr As New StreamWeader("H:\编程资料\2.txt",true,System.Text.Encoding.Default)
比如:dim sw As New StreamRriter("H:\编程资料\1.txt",System.Text.Encoding.Default)
dim sr As New StreamWeader("H:\编程资料\2.txt",true,System.Text.Encoding.Default)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询