I've written a program in VB.net. I need to open a file in binary mode and
edit it. I cannot find a way to partially overwrite existing data. There
are certain hex values I need to replace in the file. I am looking at the
System.IO.Binar yWriter class. There only seems to be a way to append or
completely truncate the contents of a file. Does anybody have an idea how I
might accomplish this??
Thanks,
Christine 5 5601
I should state that I actually want to delete parts of the binary data also
(but not all of it).
-Christine
"Christine Nguyen" <hc********@hot mail.com> wrote in message
news:e7******** ******@TK2MSFTN GP10.phx.gbl... I've written a program in VB.net. I need to open a file in binary mode
and edit it. I cannot find a way to partially overwrite existing data. There are certain hex values I need to replace in the file. I am looking at the System.IO.Binar yWriter class. There only seems to be a way to append or completely truncate the contents of a file. Does anybody have an idea how
I might accomplish this??
Thanks, Christine
"Christine Nguyen" <hc********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. I should state that I actually want to delete parts of the binary data also (but not all of it).
-Christine
"Christine Nguyen" <hc********@hot mail.com> wrote in message news:e7******** ******@TK2MSFTN GP10.phx.gbl... I've written a program in VB.net. I need to open a file in binary mode and edit it. I cannot find a way to partially overwrite existing data. There are certain hex values I need to replace in the file. I am looking at the System.IO.Binar yWriter class. There only seems to be a way to append or completely truncate the contents of a file. Does anybody have an idea how I might accomplish this??
Thanks, Christine
I don't think you can edit a file directly on the disk.
You have to load the file into an array or other structure using a streamreader,
then operate on it, and then overwrite the file using a streamwriter.
"Jon Skeet" <sk***@pobox.co m> wrote in message
news:MP******** *************** @news.microsoft .com... Chris Devol <xy*@defghijk.l mn> wrote: I don't think you can edit a file directly on the disk.
Yes you can - there's no problem doing that. You can't insert or delete bits from the start of middle of the file, of course, but that's a different matter.
It seems to me that inserting and deleting is what "editing" is. So if you can't
insert/delete then you can't edit. Or am I missing something? You have to load the file into an array or other structure using a streamreader, then operate on it, and then overwrite the file using a streamwriter.
Note that StreamReader and StreamWriter are meant for text operations, not the binary operations Christine is interested in.
That's true. I should have said "BinaryReader". .........
Chris Devol <xy*@defghijk.l mn> wrote: Chris Devol <xy*@defghijk.l mn> wrote: I don't think you can edit a file directly on the disk.
Yes you can - there's no problem doing that. You can't insert or delete bits from the start of middle of the file, of course, but that's a different matter.
It seems to me that inserting and deleting is what "editing" is. So if you can't insert/delete then you can't edit. Or am I missing something?
Yes. You can overwrite. Consider a file which has fixed length records
- it's perfectly possible to overwrite those records with new ones.
Alternatively, you might have something which goes through an assembly
marking all public methods as internal, or vice versa - something which
just requires changing a single byte for each method. No need to read
the whole file in and write it all out again.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Hi,
I accomplished using the FileStream Class. It will do binary operations and
insert without copying to a temp file and will delete at the tail end of the
file using Filestream.SetL ength.
Thanks,
Christine
"Chris Dunaway" <dunawayc@_lunc hmeat_sbcglobal .net> wrote in message
news:Xn******** *********@207.4 6.248.16... "Christine Nguyen" <hc********@hot mail.com> wrote in news:e7******** ******@TK2MSFTN GP10.phx.gbl:
I've written a program in VB.net. I need to open a file in binary mode and edit it. I cannot find a way to partially overwrite existing data. There are certain hex values I need to replace in the file. I am looking at the System.IO.Binar yWriter class. There only seems to be a way to append or completely truncate the contents of a file. Does anybody have an idea how I might accomplish this??
The BinaryWriter class has a seek method which you can use to position the file pointer at any point and overwrite the data at that position.
As far as inserting, you will have to use a temp file and read all the
data up to the insertion point, write that data to the temp file, then write
the data you want to insert to the temp file, and finally read the remaining data and write it to the temp file. Assuming all has gone well, delete
the original file and rename the temp file.
A similar procedure must be used to delete information from a file.
Chris
-- If you don't like lunchmeat, please remove it from my e-mail address to send me an e-mail This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Gord |
last post by:
Hello,
If you set the flag for an overwrite prompt using the 'Save' common dialog,
how do you read the response when the user clicks the Yes or No in the
'overwrite' message box?
Everything I've read explains about setting the flag to bring up the
overwrite prompt message box, but there's no explanation on how to read the
response to it. It appears that clicking the Yes option doesn't actually
overwrite the old file, so I assume I'm...
|
by: Florian Preknya |
last post by:
Is there a posibility to overwrite a private method (one that starts with
__ ) ? I read that they are just formely private, they are prefixed with the
class name to have an obtured visibility, so maybe it's a trick here...
More details...
I use wxPython, more specifically the wxColumnSorterMixin class. I want to
overwrite the __OnColClick event handler to behave on my way: I want the
sorting feature will affect only some columns, not all...
|
by: yaipa |
last post by:
What would be the common sense way of finding a binary pattern in a
..bin file, say some 200 bytes, and replacing it with an updated pattern
of the same length at the same offset?
Also, the pattern can occur on any byte boundary in the file, so
chunking through the code at 16 bytes a frame maybe a problem. The
file itself isn't so large, maybe 32 kbytes is all and the need for
speed is not so great, but the need for accuracy in the...
|
by: Matt |
last post by:
I'd like to overwrite just one line of a binary file, based on a
position set by seek(). Is there no way to do this? As far as I can
tell I need to read the whole file, change the line, and write it all
back out. Not exactly easy on the memory, but I see no other solution.
so far:
patchme.seek(offset)
patchme.write(a2b_hex(edit)) # the data is in hex first
patchme.close
|
by: Steven T. Hatton |
last post by:
§27.4.2.1.4 Type ios_base::openmode
Says this about the std::ios::binary openmode flag:
*binary*: perform input and output in binary mode (as opposed to text mode)
And that is basically _all_ it says about it. What the heck does the binary
flag mean?
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in...
| |
by: Lisa Pearlson |
last post by:
Hi,
My php application (on Apache/Linux) needs to do the following:
The PHP script receives a request from a client (binary), asking for certain
records of data.
My PHP script loops through all records and sends each of them ONE BY ONE.
After each record that my server script sends, it waits for the client to
confirm proper reception with an ACK (binary digit).
When there are no more records, my server script sends the client a binary
|
by: Someonekicked |
last post by:
I have a binary file, and I need to delete a specific number of characters
in it.
The file contains records, each record has a specific length.
So the way I wanna handle deleting is that I will overwrite the record I
want to delete with the last record in the file, then actually delete that
last record in the file. the problem Im having is how to delete that last
record in the file.
Suppose each record is of length 43, then I have...
|
by: B-Dog |
last post by:
Is there a way to make vb.net to overwrite the file when moving? Here is
what I'm trying to do:
If System.IO.File.Exists(dest) Then
'handle overwrite here
If MessageBox.Show("Do you want to overwrite", "Overwrite File?",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
|
by: Christine Nguyen |
last post by:
I've written a program in VB.net. I need to open a file in binary mode and
edit it. I cannot find a way to partially overwrite existing data. There
are certain hex values I need to replace in the file. I am looking at the
System.IO.BinaryWriter class. There only seems to be a way to append or
completely truncate the contents of a file. Does anybody have an idea how I
might accomplish this??
Thanks,
Christine
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |