如何从文件中获取流 [英] How Do I Get Stream From File
问题描述
我想问..
如何从vb.net中的文件获取流?
i想要将该流保存在数据库中...并在我的数据库中,我设置数据类型varbinary(max)来保存流
希望你能帮助我:)
非常感谢
To Stream:
Dim fs 作为 IO.FileStream
fs = 新 FileStream( 文件路径,FileMode.Open)
To字节数组:
*使用FileSystem
Dim readBytes(LengthYouWantToRead - < span class =code-digit> 1 )作为 字节
fs .Read(readBytes, 0 ,LengthYouWantToRead)
*使用IO。文件
Dim readBytes() As 字节
readBytes = IO.File.ReadAllBytes( 文件路径)
(FileStream示例)
如果你想阅读来自文件的4096字节,
这样编写你的代码:
Dim readBytes( 4096 - 1 )作为 字节
fs.Read(readBytes, 0 , 4096 )
检查这些:
1. saving-and-retrieving-file-使用-FILESTREAM-SQL- server-2008.aspx [ ^ ]
2. add-and-reading-files-from-sql-server-2008-filestream [ ^ ]
您可以直接使用ReadAllBytes()
文件Stream的System.IO.File
的共享功能。请参阅以下代码:
Dim _mFileBytes As Byte ()= System.IO.File.ReadAllBytes( 您的文件路径)
之后您可以直接保存此字节
数组(在数据库中的上述示例 _mFileBytes 中,其列具有数据类型Varbinary()
。
欲了解更多详情:如何在SQL Server数据库表(VB.NET)中插入字节数组。 [ ^ ]
我希望这会对你有所帮助。 :)
i want to ask..
how do i get stream from file in vb.net?
i want to save that stream in database..and in my database, i set data type varbinary (max) to save stream
hope you can help me :)
thanks very much
To Stream:
Dim fs As IO.FileStream fs = New FileStream("File Path", FileMode.Open)
To Byte Array:
* Using FileSystem
Dim readBytes(LengthYouWantToRead - 1) As Byte fs.Read(readBytes, 0, LengthYouWantToRead)
* Using IO.File
Dim readBytes() As Byte readBytes = IO.File.ReadAllBytes("File Path")
(FileStream Example)
If you want to read 4096 Bytes from file,
write your code like this:
Dim readBytes(4096 - 1) As Byte fs.Read(readBytes, 0, 4096)
Check these out:
1. saving-and-retrieving-file-using-filestream-sql-server-2008.aspx[^]
2. adding-and-reading-files-from-sql-server-2008-filestream[^]
You can Directly useReadAllBytes()
Shared Function ofSystem.IO.File
insted of file Stream. See the below code :
Dim _mFileBytes As Byte() = System.IO.File.ReadAllBytes("Your File Path")
After that you can directly save thisByte
Array (In above example _mFileBytes) in the Database with the column having Data TypeVarbinary()
.
For more Details : How to Insert Byte Array In SQL Server Database Table(VB.NET).[^]
I hope this will help you. :)
这篇关于如何从文件中获取流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!