473,654 Members | 3,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file reading/writing

Hi,
I need to read a file and simultaneously modify the same file , i.e, read
a file and then change some contents in it and then save it once again.

How do I do this?

Thanks,
Nov 16 '05 #1
5 2064
Hi Venkat,

Try reading the file, modify in memory and write everything back to the
file.
--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Any samples pls?

"Morten Wennevik" wrote:
Hi Venkat,

Try reading the file, modify in memory and write everything back to the
file.
--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #3
=?Utf-8?B?VmVua2F0?= <Ve****@discuss ions.microsoft. com> wrote in
news:5F******** *************** ***********@mic rosoft.com:
Any samples pls?


Without knowing what your file contains thats quite impossible. I dount
you'll get anyone to write the code for you anyways though - we all have jobs
too. ;)
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
Nov 16 '05 #4
Venkat,
I have a job too but I will take a minute to tell you about this wonderful
place of the internet.
Check this out. http://www.google.com/search?q=csharp+read+write+file

Hope it helps.
-- Landi

"Venkat" <Ve****@discuss ions.microsoft. com> wrote in message
news:46******** *************** ***********@mic rosoft.com...
Hi,
I need to read a file and simultaneously modify the same file , i.e, read a file and then change some contents in it and then save it once again.

How do I do this?

Thanks,

Nov 16 '05 #5
Hello Venkat,

Your problem is way too vague to actually answer with a single answer.

Let's say you have a file that is not composed of fixed length strings. The
file contains the string "ABC DEF GHI" and you want to replace this entire
string with "ZYX". Well, the new string is shorter than the old one... so
you have to move up the rest of the bytes in the file to fill in the "hole"
you left. On the other hand, you may be substituting a longer string, and
your problem is reversed. What if you want to make more than one change in
a pass? What if you have pattern matching logic that you need to apply?

And these considerations are different if you are talking about updating the
contents of a file containing only fixed length records, or using a more
complicate encoding scheme like Shift-JIS, or using a structured mechanism
like XML sitting on top of character encoding.

If you'd like to ask a more specific question, or at least provide some
insight into the nature of your data, you may get more specific answers to
your questions.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Venkat" <Ve****@discuss ions.microsoft. com> wrote in message
news:46******** *************** ***********@mic rosoft.com...
Hi,
I need to read a file and simultaneously modify the same file , i.e,
read
a file and then change some contents in it and then save it once again.

How do I do this?

Thanks,

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1808
by: Geoffrey | last post by:
We have developed a python class that can read data files created from another application. These target files are C-ISAM files used for accounting applications so the "primary" application may be reading and/or writing to portions of the files ("records") at the same time. The python class we developed opens the requested file in 'rb' mode, reads the file header (first 512k) and using information supplied in the file header (such as...
8
9844
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out | ios::binary) to declare a file object with read/write modes turned on for working with binary data. I've tried this and my file is not created. The only time it is created is when I specify ifstream or ofstream but not fstream. I've tried removing the...
4
9823
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile = tmpfile(); /* write into tmpFile */ ...
0
3930
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
6
1703
by: sandorf | last post by:
I'm new to python. Have a simple question. "open" function can only open an existing file and raise a IOerror when the given file does not exist. How can I creat a new file then?
16
7175
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte (all other data in that file should remain unchanged). How can I do that in Python? Claudio Grondi
14
2799
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given by df -k lopgod10:~/mycrfile # df -k /mnt/mvdg1/vset Filesystem 1K-blocks Used Available Use% Mounted on
1
64094
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
4
2408
by: JimmyKoolPantz | last post by:
IDE: VB2005 FILE TYPE: DBF5 I appoligize if I am posting in the wrong group. Question: Is there a position in the dbf file structure that will allow me to delete a field, such as, the way the dbf file structure has a record deletion flag? I have wrote a class for reading and writing dbf files but I recently came across the need to delete fields quickly. I'm currently reading the records into a dataset and then
13
10397
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another set of integers stored in an array.It would be a great help if you could provide some code for it.I tried the function fscanf but by that I am able to read only the first integer of the text file.Please help me.
0
8296
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,...
0
8816
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, 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...
0
8710
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 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...
1
8497
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
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...
0
5627
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();...
0
4150
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...
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.