473,399 Members | 2,478 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,399 software developers and data experts.

What is the easiest way to open a textfile for append or create it for text append?

I would like to append text to a file which might exist or not.

What is the easiest way to open or create it depending if it exists or not
and to set it into an "append" text mode?
May 22 '07 #1
3 2550
"Wolfgang Meister" <wm******@hotmail.comwrote in message
news:46***********************@newsspool1.arcor-online.net...
>I would like to append text to a file which might exist or not.

What is the easiest way to open or create it depending if it exists or not
and to set it into an "append" text mode?
Just do it -

FileStream fs = new FileStream("your_path", FileMode.Append);

.... or were you looking for something else?

-cd
May 22 '07 #2
Something like this for a file with full path stored in 'path' variable:

StreamWriter writer = null;

if (File.Exists(path))

{

writer = new StreamWriter(path, true);

}

else

{

writer = new StreamWriter(File.Create(path));

}

writer.WriteLine("Nex line or whatever else"));

writer.WriteLine("Another line or whatever");

writer.Close();

Michael

"Wolfgang Meister" <wm******@hotmail.comwrote in message
news:46***********************@newsspool1.arcor-online.net...
>I would like to append text to a file which might exist or not.

What is the easiest way to open or create it depending if it exists or not
and to set it into an "append" text mode?


May 22 '07 #3
On May 22, 3:28 pm, wmeis...@hotmail.com (Wolfgang Meister) wrote:
I would like to append text to a file which might exist or not.

What is the easiest way to open or create it depending if it exists or not
and to set it into an "append" text mode?
I guess that:

File.AppendAllText(string path, string content);

May 23 '07 #4

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

Similar topics

8
by: DanB | last post by:
This is probably soooo simple but I can't seem to get it. I have a text file that I want users to download via a web page. I want the file to be saved to a default folder (or one that they...
7
by: Peter Proost | last post by:
Hi, I'm creating an import module to read data from old textfiles, run some calculations on them and save them to sql server. I've figured out how to do a select on textfile using a schema.ini file...
4
by: Stupid48 | last post by:
I'm trying to do a simple task but can't seem to find a solution. How do I read lines from a text file backwards. i.e. I want to select the last 20 lines of a text file and display them in...
3
by: DG | last post by:
Is there a documentation on how to build Word documents with just writing XML? Footer, header, tables, insert images, fonts, ect....
8
by: Flyzone | last post by:
Hi, i have a problem with the split function and regexp. I have a file that i want to split using the date as token. Here a sample: ----- Mon Apr 9 22:30:18 2007 text text Mon Apr 9...
10
by: silverburgh.meryl | last post by:
Hi, Can you please tell me what is the mean of 't' in the input parametre in utf8_fopen? utf8_fopen( a_file, "wt" ) Thank you.
1
by: KenSmith | last post by:
How can I append text to an existing textfile before the last line using C# Like say If I have file called text.txt I am a text I love to code Will like to put C# is good before l love...
1
lifeisgreat20009
by: lifeisgreat20009 | last post by:
This is what i am getting on running the program......... C:\PROGRA~1\Java\JDK15~1.0\bin>javac Editor.java Note: Editor.java uses or overrides a deprecated API. Note: Recompile with...
16
by: raylopez99 | last post by:
I am running out of printing paper trying to debug this...it has to be trivial, but I cannot figure it out--can you? Why am I not printing text, but just the initial string "howdy"? On the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
marktang
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,...
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
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,...
0
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...

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.