将文件加载到内存流缓冲区中并创建内容相同但文件名不同的新文件

问题描述

|| 我不知道它是否简单,因为我是编程新手。 我的要求是:在我的vb.net winform应用程序中,\“ D:\\ Project \”中存在的文件文件名将显示在DataGridView1控件中。现在,我想将这些文件一个一个地加载到内存流缓冲区中,并将标头(\“ ID \”,\“ Name \”,\“ Class \”)添加文件内容中。然后我想将这些文件保存在\“ C:\\\”中,并以\“ _ de \”作为文件名的后缀,即sample_de.csv。 谁能帮帮我吗?如果您需要更多的说明,我可以以更清晰的方式发布 非常感谢您的帮助。     

解决方法

        尝试根据您的情况调整此示例:
Imports System.Text
Imports System.IO

Module Module1

    Sub Main()
        \' Read input
        Dim inputBuffer As Byte() = File.ReadAllBytes(\".\\input.txt\")

        \' Manipulate the input
        Dim outputBuffer As Byte() = DoSomethingWithMyBuffer(inputBuffer)

        \' Add headers
        \' There are several ecodings to choose from,make sure you are using 
        \' the appropriate encoder for your file.
        Dim outputTextFromBuffer As String = Encoding.UTF8.GetString(outputBuffer)
        Dim finalOutputBuilder As StringBuilder = New StringBuilder()
        finalOutputBuilder.AppendLine(\"\"\"ID\"\",\"\"Name\"\",\"\"Class\"\"\")
        finalOutputBuilder.Append(outputTextFromBuffer)

        \' Write output
        File.WriteAllText(\".\\output.txt\",finalOutputBuilder.ToString(),Encoding.UTF8)
    End Sub

    Private Function DoSomethingWithMyBuffer(inputBuffer As Byte()) As Byte()
        \'\' Do nothing because this is just an example
        Return inputBuffer
    End Function

End Module