问题描述
- 使用filestream 输入回车换行
-
现在在学习输入输出
在学习filestream的时候发现部门使用wirte 写回车换行
具体如下,代码是VB.NET的
Dim fsw As FileStream = New FileStream("C:stream1.txt", FileMode.Append, FileAccess.Write)Dim msg1 As String = "地点" Dim by1() As Byte = System.Text.Encoding.UTF8.GetBytes(msg1) fsw.Write(by1, 0, by1.Length) Dim by2(1) As Byte’直接写入回车换行的ASCII 值 但是下面发现还是不能实现换行 by2(0) = 13 by2(0) = 10 fsw.Write(by2, 0, by2.Length)‘无法回车换行 Dim msg2 As String = "rn 位置" ’这里也无法换行 Dim by3() As Byte by3 = System.Text.Encoding.UTF8.GetBytes(msg2) fsw.Write(by3, 0, by3.Length) fsw.Close() fsw.Dispose() Dim fsw2 As FileStream = New FileStream("C:stream1.txt", FileMode.Append, FileAccess.Write) Dim sw As StreamWriter = New StreamWriter(fsw2) sw.WriteLine() sw.WriteLine("时间")‘这里可以换行 sw.Close() sw.Dispose() fsw2.Close() fsw2.Dispose() 我觉得把回车换行写入byte 数组,在使用write 进行写入,应该可以换行了,但是没有效果。另外rn 也不能实现...暂时没有C币 所以只希望好心人能帮助我。
解决方案
用不着二进制。
File.AppendAllText(文件名,字符串)就可以了
VB不用"rn",用VbCrLf
解决方案二:
VB?vbcrlf 字符串加上 & vbcrlf
解决方案三:
谢谢 两位了,弄明白了... 不过这次没有奖励 真的抱歉
解决方案四:
Dim by2(1) As Byte
by2(0) = 13
by2(0) = 10
fsw.Write(by2, 0, by2.Length)
以上无法换行,今天考虑了一下可能是这个写法有问题(具体什么问题还不明白)
在网上看到说应该直接 是 filestream.writebyte 写入,测试了一下真的可以。
直接写
fsw.WriteByte(13)
fsw.WriteByte(10) 可以回车换行了。
时间: 2024-08-29 10:21:00