QT二进制文件读取问题 3C

一个二进制文件正常读出来的数据应该是这样的图片说明
但是我用流都出来的都是这样的
1 0 65535 65535 0 65535 0 65536 0 65536 0 0 0 0
0 nan 0 -1 0 0 0 -65536 1 0 0 0 0 -65536
0 nan 0 -65536 265006 393220 19464192 4849664 0 0 131072 -65404928 65535 131071
0 2.122e-314 0 0 0 0 1 0 0 0 0 65536 0 0
0 2.122e-314 0 -1 65536 0 -65536 0 0 65535 0 65536 0 1
65536 5.56277e-309 6 297 74 0 0 3 -996 -65536 0 65535 0 65535
4294901760 0 65536 0 0 0 65535 0 0 0 -65535 0 65535 131071
求大神指点这样的二进制二进制文件怎么读?
01 00 00 00 18 fc ff ff 00 00 00 00 00 00 00 00 ff ff 00 00 ff ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 ff ff 00 00 ff ff 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 01 00 00 00 00 00 01 00 ff ff ff ff 00 00 00 00 00 00 ff ff 2e 0b 04 00 04 00 06 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 1a fc ff ff 00 00 ff ff 01 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 01 00 00 00 00 00 00 00 ff ff ff ff 00 00 01 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 ff ff ff ff 2e 0b 04 00 04 00 06 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 1c fc ff ff 00 00 ff ff 00 00 00 00 ff ff 00 00 00 00 00 00 ff ff 00 00 00 00 ff ff 01 00 01 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 ff ff 00 00 00 00 ff ff 00 00 ff ff 01 00 00 00 ff ff ff ff ff ff 01 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 ff ff 00 00 00 00 00 00 00 00 01 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 ff ff 00 00 2e 0b 03 00 04 00 07 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 1e fc ff ff 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 ff ff 01 00 00 00 ff ff 01 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 01 00 00 00 00 00 00 00 00 00 00 00 ff ff 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 01 00 00 00 00 00 ff ff 00 00 00 00 ff ff 00 00 ff ff 01 00 00 00 01 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 ff ff 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 2e 0b 04 00 05 00 06 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 20 fc ff ff 00 00 ff ff 00 00 00 00 ff ff ff ff ff ff 01 00 00 00 01 00 00 00 ff ff 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 ff ff 00 00 00 00 00 00 01 00 ff ff 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 01 00 00 00 00 00 ff ff 00 00 00 00 00 00 ff ff 01 00 ff ff 01 00 fe ff 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 ff ff 00 00 ff ff ff ff 2e 0b 04 00 04 00 06 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 22 fc ff ff 00 00 ff ff ff ff 01 00 ff ff 00 00 ff ff 00 00 00 00 00 00 00 00 ff ff 01 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 ff ff 00 00 01 00 01 00 00 00 00 00 00 00 01 00 01 00 00 00 00 00 00 00 00 00 ff ff 01 00 ff ff 00 00 00 00 ff ff ff ff ff ff ff ff 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 ff ff 01 00 00 00 01 00 00 00 00 00 00 00 00 00 ff ff 01 00 00 00 00 00 00 00 2d 0b 04 00 04 00 06 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 24 fc ff ff 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 ff ff 00 00 01 00 ff ff 01 00 00 00 01 00 01 00 01 00 00 00 00 00 01 00 01 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 01 00 01 00 00 00 00 00 01 00 ff ff 00 00 00 00 01 00 00 00 ff ff 00 00 ff ff 00 00 ff ff 00 00 00 00 00 00 01 00 ff ff ff ff 00 00 01 00 00 00 00 00 01 00 ff ff 00 00 ff ff 01 00 01 00 00 00 00 00 ff ff 00 00 01 00 01 00 ff ff 00 00 2e 0b 05 00 05 00 06 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 26 fc ff ff 00 00 ff ff 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 01 00 00 00 ff ff 00 00 00 00 00 00 01 00 00 00 00 00 01 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 01 00 ff ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 01 00 00 00 00 00 00 00 00 00 ff ff 01 00 ff ff 00 00 01 00 00 00 ff ff 01 00 00 00 ff ff 00 00 2d 0b 04 00 04 00 06 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 28 fc ff ff 00 00 ff ff 00 00 00 00 fe ff ff ff 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 01 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 ff ff ff ff 00 00 00 00 ff ff 00 00 ff ff 01 00 00 00 01 00 01 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 ff ff 00 00 01 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 2e 0b 04 00 04 00 06 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 2a fc ff ff 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 01 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 01 00 01 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 ff ff 01 00 ff ff 00 00 01 00 00 00 00 00 ff ff 00 00 ff ff 01 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 ff ff 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 2e 0b 03 00 04 00 06 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 0b 00 00 00 2c fc ff ff 01 00 00 00 00 00 00 00 ff ff 00 00 ff ff 00 00 00 00 00 00 00 00 ff ff 00 00 01 00 00 00 01 00 00 00 00 00 01 00 01 00 01 00 00 00 00 00 01 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 01 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 2d 0b 04 00 04 00 06 00 00 00 29 01 00 00 4a 00 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 2e fc ff ff 00 00

1个回答

贴出你的原始16进制的文件内容、预期的结果和你的程序才好进一步帮你。简单来说,你的流里面读取的数据类型和你的文件格式不匹配。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
QT 二进制文件读取
用于以二进制的方式一次性读取文件的全部内容。版本是QT5.7
二进制文件读取问题
现在有文件名,读取这个文件,要求返回byte数组
关于二进制文件读取的问题
由于工作需要从一个二进制文件中,读取一串二进制数据,读取的代码如下:rnrnrnli_File = FileOpen(ls_billname,streamMode!)rnfileseek(li_file,lenrecord,frombeginning!)rnflen=flen -lenrecordrnIF flen > 32765 THENrn IF Mod(flen, 32765) = 0 THENrn loops = flen/32765rn ELSErn loops = (flen/32765) + 1rn END IFrnELSErn loops = 1rnEND IFrnFOR i = 1 to loopsrn ll_pos=FileRead(li_File,lb_read)rn lb_file+= lb_readrn nextrn//loop while ll_pos<0rnfileclose(li_file)rn////写入话单rnloops=integer(len(lb_file)/billlen)rnfor i=1 to loopsrn lb_read=blobmid(lb_file,i+(i -1)*billlen,billlen)rn this.of_savebill(string(lb_read))rnnextrn//记录新位置rnls_pos=string(ll_pos)rnupdate t_base_profile set fvalues1=:ls_pos,fvalues2=convert(char(10),getdate(),121) where fid=1402;rncommit;rnreturnrnrnrnrnrn可是,为什么我只能读出一个字符?rnrn把二进制文件用文本打开后显示如下:“A 82069102 2006-04-03,10:47:08 ;! 82214688 2006-04-03,10:58:29> ”rnrn请问我可以如何解决??
读取二进制文件读取问题?
RArray.dat中保存仰角数,仰角,和R数组的数据,数据以二进制的方式保存,存放顺序rn1)当前仰角层数,类型为4字节整型,长度为4字节rn2)有效层数的仰角,类型为4字节实型,长度为4*仰角层数 字节rn3)R数组数据,类型为4字节实型,长度为4*MaxRads*Gates**仰角层数 字节rn请问我怎么样把这3个数组数据读出来,多谢了!
二进制文件读取的问题?
假设二进制文件a.dat中存储一个2个字节的2进制数n,n的值为0XD561,rn本人用如下语句,读取出数值n:rnCFile f;rnf.Open( a.dat, CFile::modeRead, &fileException ))rnrn__int16 nRead;rnf.Read((void*)&nRead,2);rn经过跟踪发现nRead的值为0X61D5,而不是0XD561。不知为什么。并且怎么修改才能达到把n的正确值取出的目的。
二进制文件读取的四个问题
读取二进制文件,该文件中有汉字、英文字母、数字、符号这四种类型rnrnrn第一个问题:rnBinaryReader br = new BinaryReader(brfs, Encoding.GetEncoding("gb2312"));rnEncoding GB = Encoding .GetEncoding ("gb2312");rnrnrn直接读取字符:rnchar[] chbuffer = new char[20];rnchbuffer = br.ReadChars(2);rnrn显示两个汉字:中国,分别存在char[1]和char[2]中rnrnrnrnbyte[] bt = new byte[2];rnbt = br.ReadBytes(2);rnstr = GB.GetString(bt);rn显示一个汉字:中rnrn问题:char类型在二进制文件中占2个字节?我查资料怎么说是C#的char是一个字节rnrnrnrn第二个问题:rn读完“中国”这两个汉字后,接下来是个int的数字,读取方法为:rnrnbt = br.ReadBytes(4);rnstr = GB.GetString(bt);rnConsole.WriteLine(bt.ToString());rnrn显示为:System.Byte[]rnrn为什么不能正确显示数字呢?因为我想数字也是gb2312编码里的一部分啊!rnrnrnrn第三个问题:rn上边的不能正常读取数字,但是这样可以:rnint i = br.ReadInt32();rnConsole.WriteLine(i.ToString());rn不知道为什么?rnrn我的理解:Binaryreader.readint32是先调用binaryreader.readbyte(4),再用“gb2312”进行编码,不知道我理解的对不对?rnrnrnrn第四个问题:rn关于FileStream 和BinaryReader 的关系,如下:rnrnFileStream brfs = File .OpenRead (BinAdd );rnBinaryReader br = new BinaryReader(brfs);rnrn可不可以这样理解:BinaryReader 是建立在FileStream 的基础之上的,当BinaryReader.ReadInt32()之后,用FileStream.Seek()对文件流的当前位置进行重新设置,往前挪4个字节,那么再次执行BinaryReader.ReadInt32(),是否所读结果和前一次的BinaryReader.ReadInt32()所读数据一样?
二进制文件读取速度问题?
二进制文件读取速度问题?rnrn1、如果一个目录下有多个二进制文件,假设有一万个,我读取其中的一个会不会因文件多而变慢,如变慢会变慢多少rn2、通过函数读取流数据,再赋给类的成员变量,会降底多少速度rn int i =ReadInt();rn char c = ReadChar();rn3、每个读取函数如ReadInt()中都有一个判断语句 if (bPrintError),会影响多少速度rn4、new 的类实体对速度的影响大吗,请多指导
请教二进制文件读取的问题!
在读二进制文件的时候怎么结束啊?rn如:rnArrayList str=new ArrayList();rnFileStream stm=new FileStream(filename,System.IO.FileMode.Open);rnBinaryReader stmr=new BinaryReader(stm);rn rnwhile(true)rnrn tryrn rn string temp=stmr.ReadString();rn if (temp!="")rn str.Add(temp);rn rn catch (EndOfStreamException err)rn rn break;rn rn rn stm.Close();rn stmr.Close();rnrn我是通过引发异常跳出循环的!肯定是不好了!能不能有其它的方法让循环终止啊?rn谢谢!
二进制文件读取及定位的问题
二进制文件,我是这样读取并定位的rn FileStream fs = File.OpenRead("F:\\2009年工作\\LACBL2");rn BinaryReader br = new BinaryReader(fs);rn Byte[] wellname = new byte[100];rn br.BaseStream.Read(wellname, 84, 8);rn可是读出来的是“System.Byte[]”,并不是我想要的结果,请问这是怎么回事? rnrn
求教,二进制文件读取问题?
请问,有这样一个二进制文件rn 人名 字符 14 字母,数字的ASCⅡ码值减去32后保存rn 年龄 双字节数 2 rn 成绩 单字节数 1rn如何读取这种格式的文件,怎么转换呢,请指教? rn
二进制文件读取?
有一二进制文件格式如下:rn rn typedef struct tagGridDataFileHeaderrn rn short nDataType; //资料类型,2个字节rn CTime tSourceDataStartTime;//源数据的开始时间信息,对于预报结果文件,该值是最后一个实测数据的开始时间信息,4个字节rn CTime tSourceDataEndTime;//源数据的结束时间信息,对于预报结果文件,该值是最后一个实测数据的开始时间信息,4个字节rn int nMinutes;//预警时间长度信息(分钟),对于实测数据,该值为0,4个字节rn float fGridDataLeftLongitude;//左边的经度(度),4个字节rn float fGridDataTopLatitude;//上边的纬度(度),4个字节rn float fGridDataCenterLongitude;//中心经度(度),4个字节rn float fGridDataCenterLatitude;//中心纬度(度),4个字节rn float fGridDataDeltaX;//横向格距(KM),4个字节rn float fGridDataDeltaY;//纵向格距(KM),4个字节rn int nGridDataXNum;//横向格点数,4个字节rn int nGridDataYNum;//纵向格点数,4个字节rn short nType;//产品的类型,2个字节,0为实测数据的格点化产品,1为预警产品rn float fTemp[10];//备用数据,40个字节rnrn rn rnrn我现在想把它一一读出显示在文本中,我试按以下写,却写不下去,该怎么写?谢谢了!rn rn string StrTxtFileName = @"F:\DFPP200909221610.DAT";rn FileStream fs = new FileStream(StrTxtFileName, FileMode.Open);rn BinaryReader rdr = new BinaryReader(fs);rn rn Console.WriteLine(rdr.ReadUInt16().ToString());//读nDataType数据rn //读时间数据???tSourceDataStartTimern //fs.Position += 10;rn rnrn fs.Dispose();rn fs.Close();rn rdr.Close();
二进制文件读取
一个二进制文件,为BYTE型数据,如何读出?在线等待,谢谢
二进制文件读取?
文件头格式:rn4字节 XX数量 (数值为86)rn4字节 YY数量 (数值为90)rn4字节 ZZ数量 (数值为68)rn4字节 TT数量 (数值为2)rn4字节 hh步长 (数值为10)rn紧接是28个XX名称 每个XX名占10个字节rn我怎么样提取28个XX的名称,并一一显示出来,还有ZZ的数量值即68显示出来?还有能否把这二进制文件转换成文本文件以便查看?rnrn
qt QFile二进制文件读取int数据不对
使用QFile 将多种类型的数据保存成二进制文件,其中的int类型数据在读文件时发现不对rn例如200000,读取时变成212992。rnrn200000 = 0x00030d40rn212992 = 0x00034000rnrn其中0d部分没有被读取,打开保存的二进制文件,在文件所保存的数据时正确的rn原本的文件修改太多,于是针对这个问题专门写了个小程序实验rn实在找不到解决方法,求大牛指点迷津rnrnrn写文件部分rn[code=c]rnQDir *temp = new QDir;rn bool exist = temp->exists("temp");rn if(exist)rn QMessageBox::warning(this,QString::fromUtf8("创建文件夹"),QString::fromUtf8("文件夹已经存在!"));rn elsern rn bool ok = temp->mkdir("temp");rn if( ok )rn QMessageBox::warning(this,QString::fromUtf8("创建文件夹"),QString::fromUtf8("文件夹创建成功!"));rn rn QFile file("temp/myfiless.xox");rn qDebug() << file.open(QIODevice::WriteOnly );rn QDataStream out(&file);rnrn out << (quint32)0xA0B0C0D0;rn out << (qint32) 123;rn out.setVersion(QDataStream::Qt_4_8);rnrn out << QString("xaxaxaxa");rn out << QString("aaaaaaaaaa");rn out << (int) 200000;rn out << QString::fromUtf8("试试时");rnrn[/code]rn读文件部分rnrn[code=c]rnrnQString path = QFileDialog::getOpenFileName(this,rn tr("Open File"),rn ".",rn tr("Text Files(*.xox)"));rn if(!path.isEmpty()) rn QFile file(path);rn if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) rn QMessageBox::warning(this, tr("Read File"),rn tr("Cannot open file:\n%1").arg(path));rn return;rn rn QDataStream in(&file);rn quint32 magic;rn in>>magic;rn if(magic !=0xA0B0C0D0)rn rn QMessageBox::warning(this, tr("Read File"),rn QString::fromUtf8("格式不对"));rn return;rnrn rn qint32 version;rn in>>version;rn if(version < 100)rn return;rn elsern in.setVersion(QDataStream::Qt_4_8);rn QString str;rn int arr;rn in >> str;rn qDebug() << str;rn in >> str;rn qDebug() << str;rn qDebug()<< sizeof(str);rn in >> arr;rn qDebug() << arr;rn qDebug()<< sizeof(arr);rn in >> str;rn qDebug() << str;rn file.close();rn else rn QMessageBox::warning(this, tr("Path"),rn tr("You did not select any file."));rn rnrn[/code]
Qt文件读取问题
为什么我同一段程序,在linux下编译就能读出文件中的数据rn而在QtCreat下九显示The magic number is: 49rn程序如下:rn QFile file("info.txt");rn if (!file.open(QIODevice::ReadOnly | QIODevice::Text))rn qDebug()<<"haha" ;rnrn QTextStream info(&file);rn while (!info.atEnd())rn rn Qstring line = info.readLine();rn qDebug()<
<QT> 文件读取
#include &amp;lt;qfile.h&amp;gt; #include &amp;lt;QTextStream&amp;gt; QString str=ui-&amp;gt;input-&amp;gt;toPlainText(); QFile file(&quot;prog.txt&quot;); file.open(QFile::WriteOnly); QTextStream outfile(&amp;amp;file); ...
求助,关于二进制文件读取问题
想把某个二进制文件按照自己想要得格式读取,请问该怎么样来实现呢?rnrn例如:0B 01 00 22 AA ……rn 先读入[0B 01]把它变成2817,再读入[00 22 AA]把它变成8874rnrn问题:我现在定义了两个byte型的数组,a[2],b[3]。a[]读入[0B 01],b[]读入 rn [00 22 AA],可是每次decoder的时候他们总是变成a[0]=11,a[1]=1,b[0]=0,rn b[1]=34,b[2]=170。rnrn问题有点弱,还望高手不吝赐教!
关于二进制文件读取问题,谢谢!
我利用二进制方式读取文件数据。遇到这样的问题:rn在文件中一个字符串的结束标志是,十六进制的0rn我这样循环读取字符,但不对rnDo While Truern cChar = 利用二进制方式读一个字节的数据rn if AscB(cChar) = 0 thenrn Exit Dorn end ifrn sRet = sRet & cCharrnLooprn大家帮帮忙,看看该如何办?谢谢!
二进制文件读取字节比较问题?
char ss7Temp[2]=0;rnchar *s;rnifstream inf;rninf.open("20080201100830.dat");rnrnwhile(!inf.eof())rnrn inf.read((char*)&ss7Temp,1); //二进制文件,文件第一字节为aa rn if(ss7Temp[0] == 0xaa) //可以这样比较吗?如果第一个字节为aa,我比较的结果是不相等的rn ........rn elsern strcpy(s,ss7Temp); //运行时报错rnrnrn1.如何对二进制文件进行比较?rn2.如果把每次读取的一个字节放到 char *s该如何做?rn
奇怪的问题,16bit二进制文件读取
我有一二进制文件,保存的数据为16bit uint,用ultraEdit软件打开数据格式如下:rn00000000h FB 00 FE 00 04 01 00 01 FD 00 FD 00 FF 00 FE 00rn00000000h FF 00 FD 00 FE 00 FF 00 FF 00 FD 00 02 01 03 01rn.........rn我用如下代码读取数据rn FILE *pFile;rn pFile=fopen(szFileName,"rb");rn unsigned char pBuf;rn WORD **gray;rn gray=new WORD* [1024];rn for(UINT i=0;i<1024;i++)rn rn *(gray+i)=new WORD[1024];rn rn for(i=0;i<1024;i++)rn rn for(UINT j=0;j<1024;j++)rn rn fread((char*)&pBuf,2,1,pFile);rn *(*(gray+i)+j)=(WORD)pBuf;rn rn rn fclose(pFile);rn CString str;rn str.Format("%d",*(*(gray+0)+0));rn MessageBox(str);rn出现问题如下:rn第一个数字FB 00换算成十进制251,是对的rn第二个数字FE 00换算成十进制254,也是对的,rn第三个数字04 01读成了4,rn第四个数字00 01读成了0,rn...rn发现一个规则:凡是后面一个字节00的,读取的都是正确的,如第一第二个数字rn而后面是01的,要加上一个256,才与实际数字相符,如第三、第四个数字rn为什么会这样,怎样改正我这个程序rn
二进制文件读取到结构体的一个问题
文件内容为二进制,现在要读到一个长度为168的结构体中,我用rn结构体名 Index[10];rni = 0;rnwhile(i < 10)rnrn FileIn.seekg(sizeof(Index[i]) * i);rn FileIn.read((char*)&Index[i], 168);rn i++;rnrn这种方法读,第一条只能读到期32个字节,以后的每条都读不到,是怎么回事啊?
Qt读取图片有问题-应以二进制文件读取
Qt读取图片有问题-应以二进制文件读取 通过二进制图区QImage bool GetImg(QImage &amp;amp;pix, QString &amp;amp;strFileName) { QFile file(strFileName); char *m_pBuff = NULL; int m_nBuffSize; if (!file.open(QIODevice::ReadOnly)) ...
C++二进制文件读取
以下为在文件data.dat中写入1到50(不包含50)在内的所有偶数rn#includernvoid main()rnrn int i,count=0;rn ofstream out("data.dat",ios::out | ios::binary);rn if(!out)rn cout<<"不能打开文件data.dat!";rn for(i=2;i<50;i+=2)rn out.write((char*)&i,sizeof(int));rn out.close();rn cout<rnvoid main()rnrn int i,a,count=0;rn ifstream in("data.dat",ios::in|ios::binary|ios::nocreate);rn if(!in) cout<<"不能打开文件data.dat\n";return;rn for(i=1;!in.eof();i++)rn rn in.read((char*)&a,sizeof(int));rn cout<
二进制文件读取字符串
新手请教各位, 我想从一个二进制文件中提取字符串信息。 比如我有一个以下的二进制文件,rnabc?????xyzabc?????????xyzabc???????xyzabc???????????????????xyzrn每个信息都是以abc开头,xyz结尾。开头结尾中间的内容和长度是不定的。如何能把每个信息提取到vector.rnrn我能想到的方法,就是ifstream 打开文件,然后存到vector , 最后转换去vectorrnrn请问这样对吗?有更好的方法吗。 谢谢
C语言二进制文件读取
#include struct student { char name[20]; int num; int english; int math; int chinise; }data[100]; int main() { FILE *p; p = fopen("student.dic","rb"); int i=0; w
二进制文件读取进度
[code=C#]rnstring fileName=fileNamePath.Substring(fileNamePath.LastIndexOf("\\")+1);rn string NewFileName = DateTime.Now.ToString("yyMMddhhmmss") + DateTime.Now.Millisecond.ToString()+fileNamePath.Substring(fileNamePath.LastIndexOf("."));rn string fileNameExt = fileNamePath.Substring(fileNamePath.LastIndexOf(".") + 1);rn if(uriString.EndsWith("/")==false)rn uriString +="/";rn uriString = uriString + NewFileName;rn WebClient myWebCleint = new WebClient();rn myWebCleint.Credentials = CredentialCache.DefaultCredentials;//获取系统凭据rn //要上传的文件rn FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);rn BinaryReader r = new BinaryReader(fs);rn rn tryrn rn byte[] postArray =r.ReadBytes((int)fs.Length); rn Stream postStream = myWebCleint.OpenWrite(uriString, "PUT");//写文件rn progressBar1.Minimum = 0;rn progressBar1.Maximum = postArray.Length;rnrn rn if (postStream.CanWrite)rn rnrn rn progressBar1.Value = r.Read(postArray, 0, postArray.Length);rn [color=#FF0000]postStream.Write(postArray, 0, postArray.Length);[/color] MessageBox.Show("文件上传成功!");rn rn elsern rn MessageBox.Show("文件目前不可写");rn rn postStream.Close();rn rn catchrn rn MessageBox.Show("文件上传失败,请重试");rn rn[/code]rn以上是我写的利用二进制读取和写入文件,在文中红色字体那块,怎么获得文件已经读取多少了
二进制文件读取和处理
基于VC++对于自己定义的二进制文件进行了详细的操作,包括文件创建和修改
二进制文件读取效率测试
import java.io.*; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Random;/** * DataOutputStream+FileOutputS
二进制文件读取写入(一)
最近在老师推荐下,跟着田纳西大学James S. Plank的课程安排学习Unix Systems Programming Lab链接在这里: http://web.eecs.utk.edu/~plank/plank/classes/cs360/360/labs/lab2/index.html 在这里向和我一样没接触太多程序设计同学介绍一下学习过程: 为什么使用二进制IO 引自:Advanced
求助:二进制文件读取出错
已经实现了从数据库向文本的写入rn但反过来从文本读取存入数据库时,从中间某一行的某个字符开始读取信息不对,数目变得很大或很小,但不是随机的,因为每次都是同样的位置出错。数据也是一样的。rnrn struct line_structrn rn int no;rn int ibusid;rn char ibusname[16];rn int jbusid;rn char jbusname[16];rn float p;rn float q;rn float r;rn float x;rn int acdc;rn bool draw;rn char flow[16];rn int flow_x;rn int flow_y;rn float angle;rn int i_x;rn int i_y;rn int dir;rn int j_x;rn int j_y;rn ;rnrn ////////////// 在保存按钮里 读LINE表中的数据,并写入文件 /////////rn tblLine->Open();rn tblLine->First();rn while(!tblLine->Eof)rn rn strLine.no=tblLine->FieldByName("NO")->Value;rn strLine.ibusid=tblLine->FieldByName("IBUSID")->Value;rn strcpy(strLine.ibusname,VarToStr(tblLine->FieldByName("IBUSNAME")->Value).c_str());rn strLine.jbusid=tblLine->FieldByName("JBUSID")->Value;rn strcpy(strLine.jbusname,VarToStr(tblLine->FieldByName("JBUSNAME")->Value).c_str());rn strLine.p=tblLine->FieldByName("P")->Value;rn strLine.q=tblLine->FieldByName("Q")->Value;rn strLine.r=tblLine->FieldByName("R")->Value;rn strLine.x=tblLine->FieldByName("X")->Value;rn strLine.draw=tblLine->FieldByName("DRAW")->Value;rn strcpy(strLine.flow,VarToStr(tblLine->FieldByName("FLOW")->Value).c_str());rn strLine.flow_x=tblLine->FieldByName("FLOW_X")->Value;rn strLine.flow_y=tblLine->FieldByName("FLOW_Y")->Value;rn strLine.angle=tblLine->FieldByName("ANGLE")->Value;rn strLine.i_x=tblLine->FieldByName("I_X")->Value;rn strLine.i_y=tblLine->FieldByName("I_Y")->Value;rn strLine.j_y=tblLine->FieldByName("J_Y")->Value;rn strLine.i_x=tblLine->FieldByName("I_X")->Value;rn strLine.dir=tblLine->FieldByName("DIR")->Value;rn strLine.acdc=tblLine->FieldByName("ACDC")->Value;rn fseek(savefile1,sizeof(strLine)*total,SEEK_SET);rn fwrite(&strLine,sizeof(strLine),1,savefile1);rn total++;rn tblLine->Next();rn rnrn ////////////////在打开按钮里,把文件读入线路表 /////////////////////rn total++;rn fseek(savefile1,sizeof(strLine)*total,SEEK_SET);rn fread(&strLine,sizeof(strLine),1,savefile1);rn tblLine->Open();rn tblLine->First();rn while(strLine.no!=-1)rn rn tblLine->Insert();rn tblLine->FieldByName("NO")->Value=strLine.no;rn tblLine->FieldByName("IBUSID")->Value=strLine.ibusid;rn tblLine->FieldByName("IBUSNAME")->Value=strLine.ibusname;rn tblLine->FieldByName("JBUSID")->Value=strLine.jbusid;rn tblLine->FieldByName("JBUSNAME")->Value=strLine.jbusname;rn tblLine->FieldByName("P")->Value=strLine.p; //////////////读到第九行的时这里的P读出来就是-8E(-23),而前面保存第九行是对的。rn tblLine->FieldByName("Q")->Value=strLine.q;rn tblLine->FieldByName("R")->Value=strLine.r;rn tblLine->FieldByName("X")->Value=strLine.x;rn tblLine->FieldByName("DRAW")->Value=strLine.draw;rn tblLine->FieldByName("FLOW")->Value=strLine.flow;rn tblLine->FieldByName("FLOW_X")->Value=strLine.flow_x;rn tblLine->FieldByName("FLOW_Y")->Value=strLine.flow_y;rn tblLine->FieldByName("ANGLE")->Value=strLine.angle;rn tblLine->FieldByName("I_X")->Value=strLine.i_x;rn tblLine->FieldByName("I_Y")->Value=strLine.i_y;rn tblLine->FieldByName("J_Y")->Value=strLine.j_y;rn tblLine->FieldByName("J_X")->Value=strLine.j_x;rn tblLine->FieldByName("DIR")->Value=strLine.dir;rn tblLine->FieldByName("ACDC")->Value=strLine.acdc;rn tblLine->Post();rn total++;rn fseek(savefile1,sizeof(strLine)*total,SEEK_SET);rn fread(&strLine,sizeof(strLine),1,savefile1);rn rnrn
关于二进制文件读取,有意思。
我想读取二进制文件,由于delphi最小数制单位为byte,即一个字节,rn我现在想实现的是: rn每次读取15位二进制,然后再在其首位加一个标志位'1',rn然后再存成另一个文件.rnrn举例如下: rn原文件rn 01010101011111,010101010101010rn处理后文件为:rn101010101011111,1010101010101010rnrn我不知道如何只读取15位,rnrn如果每次读取2个Byte,则超出了15位,还有如何添加标志位.
二进制文件读取并保存文件
我要读取二进制文件 并将满足条件的数据保存成新的文件 其实就是想从二进制里文件提取一个png文件rnpng文件 是以 “89 50 4E”开头 以 “AE 42 60”结束。 请问怎么实现呢 谢谢了
【求教】二进制文件读取 大小端
HI 大家好 近期想实现一个文件读写的功能 但是碰到了一个疑问无法解决 请高手指引rnrn假设我要实现一个可以读写二进制文件的API 但是需要解决大小端差异rnrn情况 1) 小端处理器读取小端文件(无需转换)rnrn情况 2) 小端处理器读取大端文件(大端转小端)rnrn情况 3) 大端处理器读取小端文件(小端转大端)rnrn情况 4) 大端处理器读取大端文件(无需转换)rnrn但问题是 我如何知道当前文件是用大端还是小端存储的呢 在ISO标准中有没有相应协议来解决这个问题rnrn就我目前所知UCS字符编码中提供了BOM作为相关协议 但是二进制方面 是否也有相类似的协议可以使用rnrn或者说 文件读取的大小端差异是由应用程序本身自行制定的(例如在应用程序的生成的文件加入相应标志位)rnrn有忘有经验人士来澄清下 致谢!
python二进制文件读取
问题描述 python读取二进制文件时,想要获取读取字节的16进制(默认read返回的是ascii码)。 例如文件内容为“helloworld”,若读取1Byte,则读到的数据为’h’,但是想要得到该字符的16进制’0x68’ # cat testdata helloworld 解决方法 使用binascii库的b2a_hex将读取到的字节转换为16进制字符串即可 测试代码 1 #!/...
webservice4 二进制文件读取
webservice4 二进制文件读取 webservice4 二进制文件读取
c++二进制文件读取
c++文件读取提供可靠源代码。cpp文件
c++二进制文件读取操作?
最近我程序要用到读取一个二进制bin文件,该文件是存储形式是一个字节一存的,具体来讲就是 二进制文件 里存的是按十六进制显示为01 FF FD 03的情况,现在要做的就是把它 读出来,然后转换成 +1 -1 -3 +3,还请各位高手帮下忙了
相关热词 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法 c# gmail 发邮件 c# 多层文件