PDA

View Full Version : Reading binary data



vermarajeev
13th August 2007, 08:23
Hi guys,
Please help me to read the attached binary file "exactly" to some other file.
The copied file has to be same.
Here is the code that I use. But the copied file is modified.


QString message;
QFile f ( "m1_enc.ct" );
if ( f.open (IO_ReadOnly) )
{
// file opened successfully
QDataStream t ( &f );
// read the contents of the file into message
char* m = new char[f.size() +1];
t.readRawBytes ( m, f.size() );
message = m;
f.close();
}


QFile f ( "copied_file_enc.ct" );
if ( f.open (IO_WriteOnly) )
{
// file opened successfully
QDataStream t ( &f );
// read the contents of the file into message
t << message;
}
f.close();


In my case the copied_file_enc.ct is modified.

wysota
13th August 2007, 09:14
QFile f("input");
f.open(QFile::ReadOnly);

QFile f2("ouptut");
f2.open(QFile::WriteOnly|QFile::Truncate);

QByteArray dat = f.readAll();
f2.write(dat);
f.close();
f2.close();