vb.net读取u盘文件 vb读写文件

关于 VB.NET 2008中U盘的插拔一下代码将自动完成检测vb.net读取u盘文件:
Imports System.IO
Public Class Form1
Public Const WM_DEVICECHANGE = H219
Public Const DBT_DEVICEARRIVAL = H8000
Public Const DBT_DEVICEREMOVECOMPLETE = H8004
Dim DriveLetter As String
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_DEVICECHANGE Then
Select Case m.WParam
Case DBT_DEVICEARRIVAL
Dim s() As DriveInfo = DriveInfo.GetDrives
For Each drive As DriveInfo In s
If drive.DriveType = DriveType.Removable Then
【vb.net读取u盘文件 vb读写文件】DriveLetter = drive.Name.ToString()
Debug.WriteLine("U盘 :"DriveLetter"已插入.")
End If
Next
Case DBT_DEVICEREMOVECOMPLETE
Dim s() As DriveInfo = DriveInfo.GetDrives
For Each drive As DriveInfo In s
If drive.ToString = DriveLetter Then Exit Sub
Next
Debug.WriteLine("U盘:"DriveLetter"已卸载vb.net读取u盘文件!")
End Select
End If
MyBase.WndProc(m)
End Sub
End Class
vb.net读取文件流dim filename as string = "文件名" Using myfilestream As New FileStream(FileName, FileMode.Open, FileAccess.Read)
Dim data() As Byte
ReDim data(myfilestream.Length - 1)
myfilestream.Read(data, 0, myfilestream.Length)
myfilestream.Close()
' data是你要的结果,为byte() , End Using
vb.net编程接受U盘准备卸载用的windows消息 DBT_DEVICEQUERYREMOVE总是没反应,据说是因为默认注册的消息里在我的XP VB2010环境下,测试U盘插入拔出,没有问题:
Private WM_DEVICECHANGE As Integer = H219
Public Enum WM_DEVICECHANGE_WPPARAMS As Integer
DBT_CONFIGCHANGECANCELED = H19
DBT_CONFIGCHANGED = H18
DBT_CUSTOMEVENT = H8006
DBT_DEVICEARRIVAL = H8000
DBT_DEVICEQUERYREMOVE = H8001
DBT_DEVICEQUERYREMOVEFAILED = H8002
DBT_DEVICEREMOVECOMPLETE = H8004
DBT_DEVICEREMOVEPENDING = H8003
DBT_DEVICETYPESPECIFIC = H8005
DBT_DEVNODES_CHANGED = H7
DBT_QUERYCHANGECONFIG = H17
DBT_USERDEFINED = HFFFF
End Enum
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_DEVICECHANGE Then
Select Case m.WParam
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEARRIVAL
MsgBox("USB device is just plugged in!")
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEREMOVECOMPLETE
MsgBox("USB device is just taken out")
End Select
End If
MyBase.WndProc(m)
End Sub
VB中怎样将文件复制到检测到的U盘中去FileCopy "d:\123\新建文件夹\hlyy.xls", "fbhy.txt"
改为
FileCopy "d:\123\新建文件夹\hlyy.xls", fb"hy.txt"
vb.net 读取扫描枪USB接口数据的实例USB比较难抓数据vb.net读取u盘文件 , 建议是USB模拟串口,或者直接就是串口,这样数据比较好抓 。
USB上传模式是鼠标光标在哪数据就上传在哪,所以你抓USB的数据的很难vb.net读取u盘文件!
X猫-思刊办公专营店
关于vb.net读取u盘文件和vb读写文件的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读