开发者

Loading a file into memory stream buffer and creating new file with same content and with different filename

开发者 https://www.devze.com 2023-03-09 23:29 出处:网络
I don\'t know whether it is simple or not because i am new to programming. my requirement is : In my vb.net winform application, the filenames of the files present in \"D:\\Project\"willbe displayed

I don't know whether it is simple or not because i am new to programming.

my requirement is : In my vb.net winform application, the filenames of the files present in "D:\Project" willbe displayed in DataGridView1 control. Now I want to load these files one after another into memory stream buffer and add the headers("ID","Name","开发者_StackOverflow社区Class") to the content in the file. Then I want to save these files in "C:\" with "_de" as suufix to the filename i.e.,sample_de.csv.

Can anyone please help me? If you need more clarity i can post it in more clear way

Many Thanks for your help in advance.


Try adapting this example to your situation:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消