English 中文(简体)
将文件加载到内存流缓冲区并创建具有相同内容和不同文件名的新文件
原标题:Loading a file into memory stream buffer and creating new file with same content and with different filename
  • 时间:2011-05-31 15:07:11
  •  标签:
  • vb.net

我不知道它是否简单,因为我是编程新手。

我的要求是:在我的vb.net winform应用程序中,“D:Project”中存在的文件名将显示在DataGridView1控件中。现在,我想将这些文件一个接一个地加载到内存流缓冲区中,并将头(“ID”、“Name”、“Class”)添加到文件中的内容中。然后我想将这些文件保存在“C:”中,并将“_de”作为suufix保存到文件名中,即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




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签