第一段:二进制文件读写
①.、写二进制数据到指定目录
==将barray字节数组中的数据创建在strFilename目录文件下,存储格式为二进制,False表示不添加,直接覆盖创建.
==将目录中的文件读取到barry字节数组中,即读取二进制文件.
第二段:字符文件的读写
①.、 将txtFile控件中的字符写到srtFileName指定目录,以创建方式.
①.、实现上传按钮方法代码.
VB.NET打开二进制文件用fileopen完成,打开二进制文件的形式为:openmode.binary
读取二进制文件用的是fileget方法,写入二进制文件用的是fileput方法.
应用示例:将一批随机数保存在一个dat文件中,然后再将其提取到文本框中.
二进制文件的读写一批随机数的存取,程序为:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, i, fn As Integer
Dim s As String = ""
fn = FreeFile()
FileOpen(fn, "d:\data.dat", OpenMode.Binary)
x = Int(Rnd() * 100)
s = s + Str(x)
FilePut(fn, x)
Next
FileClose(fn)
TextBox1.Text = s
End Sub
Dim x, fn As Integer
Do While Not EOF(fn)
FileGet(fn, x)
s = s + Str(x) + " "
Loop
Private Sub Command1_Click()
Dim strFile? ? ?As String
Dim intFile? ? ?As Integer
Dim strData? ? ?As String
strFile = "c:\学生成绩.txt"
intFile = FreeFile
Open strFile For Input As intFile
strData = StrConv(InputB(FileLen(strFile), intFile), vbUnicode)
Debug.Print strData
Close intFile
以上就是土嘎嘎小编为大家整理的vb.net提取文件相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!