如何将文件从文件夹加载到内存流缓冲区 [英] how to load a file from folder to memory stream buffer

查看:30
本文介绍了如何将文件从文件夹加载到内存流缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 vb.net win 表单.我的任务是将文件夹中的文件名显示到 gridview 控件上.当用户在我的 UI 中单击处理按钮时,gridview 中存在的所有文件名,相应的文件必须一个接一个地加载到内存流缓冲区中,并将标题附加到文件的内容中,并使用 _ed 将其保存在硬盘驱动器中文件名的后缀.

I am working on vb.net win form. My task is display the file names from a folder onto gridview control. when user clicks process button in my UI, all the file names present in gridview, the corresponding file has to be loaded onto memory stream buffer one after another and append the titles to the content of the file and save it in hard drive with _ed as a suffix to the file name.

我是非常基础的程序员.我已经做了以下尝试并成功地将文件名显示到 gridview 上.但不知道后面的部分.请问有什么建议吗?

I am very basic programmer. I have done the following attempt and succeeded in displaying filenames onto gridview. But no idea of later part. Any suggestions please?

'将文件夹中的文件显示到网格视图上

'Displaying files from a folder onto a gridview

    Dim inqueuePath As String = "C:\Users\Desktop\INQUEUE"
    Dim fileInfo() As String
    Dim rowint As Integer = 0
    Dim name As String
    Dim directoryInfo As New System.IO.DirectoryInfo(inqueuePath)
    fileInfo = System.IO.Directory.GetFiles(inqueuePath)

    With Gridview1
        .Columns.Add("Column 0", "FileName")
        .AutoResizeColumns()
    End With

    For Each name In fileInfo
        Gridview1.Rows.Add()
        Dim filename As String = System.IO.Path.GetFileName(name)
        Gridview1.Item(0, rowint).Value = filename
        rowint = rowint + 1
    Next

非常感谢您抽出宝贵的时间阅读这篇文章.

Thank you very much for spending your valuable time to read this post.

推荐答案

将文件读入内存流非常容易,只需查看以下示例,您应该能够将其转换为适合您的需求:

to read a file into a memorystream is quite easy, just have a look at the following example and you should be able to convert it to suite your needs:

    Dim bData As Byte()
    Dim br As BinaryReader = New BinaryReader(System.IO.File.OpenRead(Path))
    bData = br.ReadBytes(br.BaseStream.Length)
    Dim ms As MemoryStream = New MemoryStream(bData, 0, bData.Length)
    ms.Write(bData, 0, bData.Length)

然后随意使用 MemoryStream ms.只是为了清除 Path 包含您想要读入内存流的完整路径和文件名.

then just use the MemoryStream ms as you please. Just to clearify Path holds the full path and filename you want to read into your memorystream.

这篇关于如何将文件从文件夹加载到内存流缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆