473,385 Members | 1,356 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,385 software developers and data experts.

Append mode in write operation

I want to write to an output file, "C:\\temp\\debug.txt": If the file
exists, append the new content to the end of the file (instead of
overwriting the current content).

Therefore, I want to code this like below:
FileInfo lFile = new FileInfo("C:\\temp\\debug.txt");
if (lFile.Exists)
{

FileStream lStream =
lFile.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
}

However, it doesn't work because It overwrites the existing content. I
believe the append mode is defined with different parameters from the
ones I use. What are the correct parameters to define the "append"
type of write mode?

Thanks!

Oct 15 '07 #1
2 1797
Curious wrote:
I want to write to an output file, "C:\\temp\\debug.txt": If the file
exists, append the new content to the end of the file (instead of
overwriting the current content).

Therefore, I want to code this like below:
FileInfo lFile = new FileInfo("C:\\temp\\debug.txt");
if (lFile.Exists)
{

FileStream lStream =
lFile.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
}

However, it doesn't work because It overwrites the existing content. I
believe the append mode is defined with different parameters from the
ones I use. What are the correct parameters to define the "append"
type of write mode?

Thanks!
Use FileMode.Append. You don't have to check if the file exists, if it
doesn't exist it will be created.

--
Göran Andersson
_____
http://www.guffa.com
Oct 15 '07 #2
Thanks Göran! It works!

Oct 15 '07 #3

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

Similar topics

8
by: b83503104 | last post by:
Hi, I want to append one (huge) file to another (huge) file. The current way I'm doing it is to do something like: infile = open (infilename, 'r') filestr = infile.read() outfile =...
14
by: Aaron Couts | last post by:
I have a program that writes to a log file. It's compiled on RH Linux 7.3 (Kernel 2.4.18-18.7). It's using fopen in append mode. When the file reaches 51200000 bytes in size, the program will no...
5
by: Steven C | last post by:
Hello: I am trying to append a dataset that draws its data from a MSDE instance, and I keep getting the exception: Can't create a child list for field tblCustomers. conn = new...
1
by: piotrek | last post by:
Hi. I would like to ask if there is a method to force streamwriter.writeline() to write line at the end of existing file, or should i have write the method for my own. PK
1
by: Ritesh Raj Sarraf | last post by:
Hi, I've got a problem here. def compress_the_file(zip_file_name, files_to_compress, sSourceDir): """ Condenses all the files into one single file for easy transfer """ try:
2
by: richardson | last post by:
I tried to open an existing file in Append mode. The file exists and also has data. file_handle := UTL_FILE.FOPEN('/usr/oracle/rdb_logs', 'pacs_report.txt', 'A');...
16
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good)...
1
by: Curious | last post by:
I want to write to an output file, "C:\\temp\\debug.txt": If the file exists, append the new content to the end of the file (instead of overwriting the current content). If the file doesn't exist,...
15
by: =?ISO-8859-15?Q?L=E9na=EFc?= Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all, For some reasons, somewhere in a program, I'd like, if possible, to quickly parse a whole file before rewinding it and letting the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.