将文件传递给函数的最佳方法

时间:2021-08-11 11:03:02

I'm working on a VB.NET DLL right now, and one of the functions I'm writing is supposed to take a file, and clip out an array of bytes (the method I've got works, and can be abstracted away here). What's the best way to pass a file to this function? Would passing a filename to it be best, or what would be the best way to accomplish this?

我现在正在研究一个VB.NET DLL,我正在编写的一个函数应该是一个文件,并剪切出一个字节数组(我已经得到的方法,可以抽象出来)这里)。将文件传递给此函数的最佳方法是什么?将文件名传递给它是最好的,或者最好的方法是什么?

2 个解决方案

#1


FileStream Class

sample from the link above

来自上面链接的样本

Private Shared Sub AddText(ByVal fs As FileStream, ByVal value As String)
    Dim info As Byte() = New UTF8Encoding(True).GetBytes(value)
    fs.Write(info, 0, info.Length)
End Sub

#2


Filenames as a string are an old school standard method of dealing with files. Its a parameter that people know how to set correctly and use.

文件名作为字符串是处理文件的旧学校标准方法。它是一个人们知道如何正确设置和使用的参数。

I agree with Fredou above and Greg D that a FileStream is the best way to go. They are just easier to do things the right way with.

我同意上面的Fredou和Greg D认为FileStream是最好的方法。他们更容易以正确的方式做事。

#1


FileStream Class

sample from the link above

来自上面链接的样本

Private Shared Sub AddText(ByVal fs As FileStream, ByVal value As String)
    Dim info As Byte() = New UTF8Encoding(True).GetBytes(value)
    fs.Write(info, 0, info.Length)
End Sub

#2


Filenames as a string are an old school standard method of dealing with files. Its a parameter that people know how to set correctly and use.

文件名作为字符串是处理文件的旧学校标准方法。它是一个人们知道如何正确设置和使用的参数。

I agree with Fredou above and Greg D that a FileStream is the best way to go. They are just easier to do things the right way with.

我同意上面的Fredou和Greg D认为FileStream是最好的方法。他们更容易以正确的方式做事。