delphi 读取u盘,u盘以16进制存储 u盘以16进制存储,例如:0A AA 3A FF 4A B3 55 3B 4F 没有文件格式。如果有文件格式,还好读取,例如:0A AA 3A FF 4A B3 55 3B 4F 放在test.txt文档中 这样还好读。但现在没有,怎么读取 希望高手给解决一下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的意思我不理解了。你指优盘没有磁盘格式?没有FAT32、NTFS等格式?做加密狗?那我就不会了…… hPartition := CreateFile('\\\\.\\i:', GENERIC_READ,FILE_SHARE_READ,0, OPEN_EXISTING, 0, 0);把分区当成一个文件设备来读.这里面假定是i盘.里面读写的是磁盘扇区内容 楼上老兄的方法是对的,给你一段我写的读取SD卡的程序,我懒得整理了,自己找找有用的Procedure Tfrmmain.suiButton28Click(Sender : TObject);Var driver : pchar; block_size : Integer; start_num , total_num , num_tmp : Integer; hdevicehandle : thandle; i , j , k : Integer; C : Char; fbuf : pchar; hex_str , char_str , tmp_str : String; tem_id : String; trans_no_tmp : String; num : String; bu_count , trans_count : Integer;Begin driver := pchar('\\.\' + DriveComboBox1.Drive + ':'); block_size := 512; start_num := 0; total_num := 1; hdevicehandle := CreateFile(driver , GENERIC_ALL , FILE_SHARE_READ Or FILE_SHARE_WRITE , Nil , OPEN_EXISTING , 0 , 0); If (hdevicehandle <> INVALID_HANDLE_VALUE) Then Begin fbuf := allocmem(total_num * block_size); FileSeek(hdevicehandle , start_num * block_size , 0); If FileRead(hdevicehandle , fbuf[0] , total_num * block_size) <> total_num * block_size Then Raise exception.Create('读磁盘错误!'); char_str := strpas(fbuf); memosd.Lines.Add('字符【' + char_str + '】'); memosd.Lines.Add('读取包头结束!'); freemem(fbuf); closehandle(hdevicehandle); End; tmp_str := copy(char_str , 1 , 10); If trystrtoint(tmp_str , bu_count) = false Then Begin memosd.Lines.Add('补货记录总条数不是合法的整数!'); exit; End; tmp_str := ''; tmp_str := copy(char_str , 11 , 10); If trystrtoint(tmp_str , trans_count) = false Then Begin memosd.Lines.Add('交易记录总条数不是合法的整数!'); exit; End; tem_id := copy(char_str , 21 , 8); del_bu_tmp(tem_id); write_bu_con_tmp(tem_id , inttostr(bu_count) , ''); start_num := 1; While start_num <= bu_count Do Begin hdevicehandle := CreateFile(driver , GENERIC_ALL , FILE_SHARE_READ Or FILE_SHARE_WRITE , Nil , OPEN_EXISTING , 0 , 0); If (hdevicehandle <> INVALID_HANDLE_VALUE) Then Begin fbuf := allocmem(block_size); FileSeek(hdevicehandle , start_num * block_size , 0); If FileRead(hdevicehandle , fbuf[0] , block_size) <> block_size Then Raise exception.Create('读磁盘错误!'); char_str := strpas(fbuf); memosd.Lines.Add('字符【' + char_str + '】'); memosd.Lines.Add('读取补货记录' + inttostr(start_num) + '结束!'); freemem(fbuf); closehandle(hdevicehandle); End; do_sd(char_str , tmp_str); start_num := start_num + 1; End; i := bi_bu_mixi_sd(tem_id); If i = 2 Then Begin write_bu_from_tmp(tem_id); End; char_str := ''; tmp_str := ''; start_num := 301; del_trans_tmp(tem_id); write_trans_con_tmp(tem_id , inttostr(trans_count) , ''); While start_num <= (trans_count * 3 + 300) Do Begin hdevicehandle := CreateFile(driver , GENERIC_ALL , FILE_SHARE_READ Or FILE_SHARE_WRITE , Nil , OPEN_EXISTING , 0 , 0); If (hdevicehandle <> INVALID_HANDLE_VALUE) Then Begin fbuf := allocmem(3 * block_size); FileSeek(hdevicehandle , start_num * block_size , 0); If FileRead(hdevicehandle , fbuf[0] , 3 * block_size) <> 3 * block_size Then Raise exception.Create('读磁盘错误!'); char_str := strpas(fbuf); memosd.Lines.Add('字符【' + char_str + '】'); memosd.Lines.Add('读取交易记录' + inttostr(start_num) + '结束!'); freemem(fbuf); closehandle(hdevicehandle); End; do_sd(char_str , tmp_str); start_num := start_num + 3; End; i := bi_trans_mixi_sd(tem_id); If i = 2 Then Begin write_trans_from_tmp(tem_id); End; frmdatamu.Message1.Text := '读取SD卡结束!'; frmdatamu.Message1.ShowModal;End; 楼主好像没把问题说明清楚三个问题1.数据类型2.存储方式3.文件格式楼主说的是数据类型是 二进制 存储方式没说清 文件格式也没说清我猜是不是想直接从U盘Block中读出二进制数据? 楼主的意思我大概明白,你是想要进行扇区级读写,直接读取卡内的每个字节的数据出来。SD卡我不清楚,U盘的话你的去了解一下文件系统,因为文件系统可以帮助你定位你所要找的文件地址从而正确读写你要的内容。SD卡,应该也有目录项什么的。 random()取随机数字,数据溢出===>亟待高手解决 Delphi代码转换为VB代码 这个问题提了老半天没人解决,另开贴给分...得到其他Exe菜单项的ID,并执行 如果使udp接收取消息的时候能发出声音?? 找书的都进来一下,我有的是,没地方放呀 非模态窗口的问题 求助 ~ rave 11.0.5 怎么解决? down了Kylix,但是一个里面包括了***.rar,***.r001-r030????? 如何对一字符串的某一特定位的字符进行操作,如:判断每一个字符是否为‘-’,如果是则将它删除。 Kingron(WinAPI),接 关于动态创建问题 delphi初学者的迷惑
把分区当成一个文件设备来读.这里面假定是i盘.
里面读写的是磁盘扇区内容
Procedure Tfrmmain.suiButton28Click(Sender : TObject);
Var
driver : pchar;
block_size : Integer;
start_num , total_num , num_tmp : Integer;
hdevicehandle : thandle;
i , j , k : Integer;
C : Char;
fbuf : pchar;
hex_str , char_str , tmp_str : String;
tem_id : String;
trans_no_tmp : String;
num : String;
bu_count , trans_count : Integer;
Begin
driver := pchar('\\.\' + DriveComboBox1.Drive + ':');
block_size := 512;
start_num := 0;
total_num := 1; hdevicehandle := CreateFile(driver , GENERIC_ALL , FILE_SHARE_READ Or FILE_SHARE_WRITE , Nil , OPEN_EXISTING , 0 , 0); If (hdevicehandle <> INVALID_HANDLE_VALUE) Then
Begin
fbuf := allocmem(total_num * block_size);
FileSeek(hdevicehandle , start_num * block_size , 0); If FileRead(hdevicehandle , fbuf[0] , total_num * block_size) <> total_num * block_size Then
Raise exception.Create('读磁盘错误!'); char_str := strpas(fbuf);
memosd.Lines.Add('字符【' + char_str + '】');
memosd.Lines.Add('读取包头结束!');
freemem(fbuf);
closehandle(hdevicehandle);
End; tmp_str := copy(char_str , 1 , 10);
If trystrtoint(tmp_str , bu_count) = false Then
Begin
memosd.Lines.Add('补货记录总条数不是合法的整数!');
exit;
End; tmp_str := '';
tmp_str := copy(char_str , 11 , 10);
If trystrtoint(tmp_str , trans_count) = false Then
Begin
memosd.Lines.Add('交易记录总条数不是合法的整数!');
exit;
End; tem_id := copy(char_str , 21 , 8); del_bu_tmp(tem_id);
write_bu_con_tmp(tem_id , inttostr(bu_count) , ''); start_num := 1; While start_num <= bu_count Do
Begin
hdevicehandle := CreateFile(driver , GENERIC_ALL , FILE_SHARE_READ Or FILE_SHARE_WRITE , Nil , OPEN_EXISTING , 0 , 0);
If (hdevicehandle <> INVALID_HANDLE_VALUE) Then
Begin
fbuf := allocmem(block_size);
FileSeek(hdevicehandle , start_num * block_size , 0); If FileRead(hdevicehandle , fbuf[0] , block_size) <> block_size Then
Raise exception.Create('读磁盘错误!'); char_str := strpas(fbuf);
memosd.Lines.Add('字符【' + char_str + '】');
memosd.Lines.Add('读取补货记录' + inttostr(start_num) + '结束!');
freemem(fbuf);
closehandle(hdevicehandle);
End;
do_sd(char_str , tmp_str);
start_num := start_num + 1;
End; i := bi_bu_mixi_sd(tem_id);
If i = 2 Then
Begin
write_bu_from_tmp(tem_id);
End; char_str := '';
tmp_str := '';
start_num := 301;
del_trans_tmp(tem_id);
write_trans_con_tmp(tem_id , inttostr(trans_count) , ''); While start_num <= (trans_count * 3 + 300) Do
Begin
hdevicehandle := CreateFile(driver , GENERIC_ALL , FILE_SHARE_READ Or FILE_SHARE_WRITE , Nil , OPEN_EXISTING , 0 , 0);
If (hdevicehandle <> INVALID_HANDLE_VALUE) Then
Begin
fbuf := allocmem(3 * block_size);
FileSeek(hdevicehandle , start_num * block_size , 0); If FileRead(hdevicehandle , fbuf[0] , 3 * block_size) <> 3 * block_size Then
Raise exception.Create('读磁盘错误!'); char_str := strpas(fbuf);
memosd.Lines.Add('字符【' + char_str + '】');
memosd.Lines.Add('读取交易记录' + inttostr(start_num) + '结束!');
freemem(fbuf);
closehandle(hdevicehandle);
End;
do_sd(char_str , tmp_str);
start_num := start_num + 3;
End; i := bi_trans_mixi_sd(tem_id);
If i = 2 Then
Begin
write_trans_from_tmp(tem_id);
End; frmdatamu.Message1.Text := '读取SD卡结束!';
frmdatamu.Message1.ShowModal;End;