实名认证用户熊川湘 身份证号码430811198506290914

StreamReader文件流的输入和输出

本人在学习vb .net过程中,在用到StreamWriter读入中文时出现了乱码的问题。经摸索,发现了解决方法(求助无门回答,只好自己试验):

Dim file1 As System.IO.StreamReader = New System.IO.StreamReader _
("\aaa.text", System.Text.Encoding.GetEncoding("gb2312"))
str = file1.ReadLine()
读中文数据就没问题了;

注意:在这种格式下,1个中文相当于1个英文字符(而不是2个)。

文件输出:
dim str as string
Dim file2 As System.IO.StreamWriter = New System.IO.StreamWriter _
("\bbb.text", False, System.Text.Encoding.GetEncoding("gb2312"))
file2.WriteLine(str)
file2.Close()
' Me.Dispose()

输出文件多一个False,这是表示输出文件从头开始,如果是true,表示append,即输入的数据添加到文件后面。

 

引用地址:http://bbs.bccn.net/viewthread.php?tid=85932&extra=page%3D1%26amp%3Bfilter%3Ddigest

posted @ 2008-11-26 15:48  浪达短信群发  阅读(416)  评论(0编辑  收藏  举报