473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

insert bytes to a file

10
I need save huge data in a file in byte format.Sometimes i have to insert some bytes in a special position.I use FileStream,but i can only append byte at the end of the file or rewrite data in the file.So how can i insert bytes into the file without destroy other data?

thanks
Sep 18 '07 #1
4 1294
Shashi Sadasivan
1,435 Expert 1GB
I would say read the whole file.
Write it back to the file until you reach your "special position"
Write your "special data"
and write back all the rest of the file that is left
Sep 18 '07 #2
ansuhua
10
I would say read the whole file.
Write it back to the file until you reach your "special position"
Write your "special data"
and write back all the rest of the file that is left
thanks ,do you mean that i should move the rest of the file to another file and then move back?
My file is big,Maybe 200M~2000M.I think it will be slow to move so many data.
Sep 18 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
In that case, you may want to read the file upto the point where you want to start writing.
Copy all the data from there onwards, write your new data, and write the copied data.

If you want to reduce that (maybe because you might want to inser your data early in the file => worst case, right at the begining)
you may want to read the file in chunks.

So if your new data is 10bytes.
read the first 10 bytes, write your 10 bytes.
Read the next 10 bytes, write the next 10 bytes, and so on.
obviously you can increase this size for a faster response,

Cheers
Sep 18 '07 #4
ansuhua
10
In that case, you may want to read the file upto the point where you want to start writing.
Copy all the data from there onwards, write your new data, and write the copied data.

If you want to reduce that (maybe because you might want to inser your data early in the file => worst case, right at the begining)
you may want to read the file in chunks.

So if your new data is 10bytes.
read the first 10 bytes, write your 10 bytes.
Read the next 10 bytes, write the next 10 bytes, and so on.
obviously you can increase this size for a faster response,

Cheers
Good idea,Thank you very much!
Sep 18 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Niraj | last post by:
Hi, I am trying to do bulk insert of binary data (array of bytes) in an Oracle table. The data type of the table is BLOB. I am using Oracle Objects for OLE (OO4O) in C++. The binary data that I...
20
by: akej via SQLMonster.com | last post by:
Hi, i have table with 15 columns CREATE TABLE . ( PRIMARY KEY , NULL , NULL , NULL , NULL , (50) NULL , NULL
5
by: dotyet | last post by:
I have been given the daunting task of sql query tuning. I am looking for ways to get started with that. I am on DB2 UDB 8.2 (8.1 with Fixpak 8) on Windows. One point which I could think about...
11
by: Sezai YILMAZ | last post by:
Hello I need high throughput while inserting into PostgreSQL. Because of that I did some PostgreSQL insert performance tests. ------------------------------------------------------------ --...
10
by: Gnafu | last post by:
(Hi to all... ^_^) I tryed theese ways: fstream riaperto( "codici.dat", ios::out|ios::binary|ios::app); if(riaperto.bad()){ cerr<<"errore di apertura"<<endl; system("Pause"); }
46
by: dunleav1 | last post by:
I have a process that does inserts that runs 50% slower that Oracle and Mssql. Queries normally take 50% slower than normal. DB2, Oracle, Mssql all are configured on same os, same disk array...
9
by: anachronic_individual | last post by:
Hi all, Is there a standard library function to insert an array of characters at a particular point in a text stream without overwriting the existing content, such that the following data in...
6
by: Gregor =?UTF-8?B?S292YcSN?= | last post by:
Hi! I'm using JDBC to connect to DB2. I have a binary data (array of bytes) and want to save them. Is it possible to write an INSERT statement to do this: INSERT INTO TABLE (ID, BYTES)...
10
by: electric_r | last post by:
Hallo, I have 2 questions: with php and mysql : 1) How can I insert a text file into a TEXT field of a table ? 2) How can I insert a microsoft word file into a BLOB field of a table ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.