vb.net中的流 vbnet filestream

vb.net读取流Imports System
Imports System.IO
Imports System.TextPublic Class Form2Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim path As String = "MyTest.txt"Try
If File.Exists(path) Then
File.Delete(path)
End If'写入流
Dim sw As StreamWriter = New StreamWriter(path)
sw.WriteLine("This")
sw.WriteLine("is some text")
sw.WriteLine("to test")
sw.WriteLine("Reading")
sw.Close()
【vb.net中的流 vbnet filestream】'读取流
'Dim sr As StreamReader = New StreamReader(path)'Do While sr.Peek() = 0
''This is an arbitrary size for this example.
'Dim c(5) As Char
'sr.Read(c, 0, c.Length)
''The output will look odd, because
''only five characters are read at a time.
''MsgBox(c)
'Loop
'sr.Close()
Catch ex As Exception
Console.WriteLine("The process failed: {0}", ex.ToString())
End TryEnd Sub'读取流
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim path As String = "MyTest.txt"Dim reader As StreamReader = New StreamReader(path)
Dim c(5) As Char
reader.Read(c, 0, c.Length)
MsgBox(c)
reader.Close()End Sub
End Class 解读Read(arrayChar[]()[], Int32, Int32) buffer 类型:arraySystem..::.Char[]()[]
此方法返回时vb.net中的流 , 包含指定vb.net中的流的字符数组,该数组vb.net中的流的 index 和 (index + count - 1) 之间vb.net中的流的值由从当前源中读取的字符替换 。index 类型:System..::.Int32
开始写入的 buffer 的索引 。count 类型:System..::.Int32
最多读取的字符数 。
VB.net文件(流)操作(重金悬赏)把vb.net中的流你的工程文件发给vb.net中的流我看看
tangzejin921@qq.com
C#,VB.net,二进制流转回Word的时候能否知道他的文件名和后缀无法直接获?。梢圆捎帽渫ǖ姆椒ǎ?思路:
把word转换成二进制流前先用变量把拓展名和后缀获取到(例如 var filename = “xxxx.doc”)
定义一个int变量记录二进制流(word)的长度 。并将该变量转成4字节的btye[]数组
将第一步中获取到的文件名字符串转成byte[]数组 。
将字节按照: word文件byte[]+文件名byte[]+word文件长度byte[](第二步)按照顺序拼接成一个byte[]数组
还原:
1.首先读取总byte[]的后4个字节,以确定文件二进制流的有效长度(假设为L).
2.将索引0至L 之间的字节数组按常规方式恢复成流.
3.将索引L至N-4之间的字节数组还原成字符串,即可获得原文件名.
然后,爱咋咋地~~~~
vb.net读取文件流dim filename as string = "文件名" Using myfilestream As New FileStream(FileName, FileMode.Open, FileAccess.Read)
Dim data() As Byte
ReDim data(myfilestream.Length - 1)
myfilestream.Read(data, 0, myfilestream.Length)
myfilestream.Close()
' data是你要的结果,为byte() , End Using
vb.net2005中提示无法在流的结尾之外进行读取我给你一个实例,你自己修改;
一,运行界面:
二,完整代码:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'写文件
Dim Myw As New FileStream(Application.StartupPath"\实验文件.txt", FileMode.Create)
Dim MyB_Write As BinaryWriter = New BinaryWriter(Myw)
MyB_Write.Write(TextBox1.Text)
Myw.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'读文件
Dim Myr As New FileStream(Application.StartupPath"\实验文件.txt", FileMode.Open, FileAccess.Read)
Myr.Position = 0
Dim MyB_Read As New BinaryReader(Myr)

推荐阅读