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

Clear the content of a file

Hello.
How do you clear the content of a *.txt file?
Thanks.

--
Xero

http://www.chezjeff.net
My personal web portal
Nov 21 '05 #1
4 7423
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> wrote in message
news:43**********************************@microsof t.com...
How do you clear the content of a *.txt file?


System.IO.File.Open( "foo.xml", System.IO.FileMode.Truncate).Close

Bit of an audacious one-liner, but you get the drift. Open the file in truncate
mode, then (as there's nothing really to do in truncate mode after having reset
the file to zero-length) close it.

Opening it with FileMode.Create will also achieve the same thing, and allow
you to use the FileStream afterwards, for instance,

Dim fileStream As System.IO.FileStream
fileStream = System.IO.File.Open( "foo.xml", System.IO.FileMode.Create)
'
' foo.xml is now zero-length, plus use can write to fileStream.
'
fileStream.Flush
fileStream.Close
Derek Harmon
Nov 21 '05 #2
Jeff,

Derek gave you the answer, however what he did not write in my opinon in
words was.

"Just create an empty one with the same name". (And than use one of his
samples)

Only meant as addition

Cor

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )>
Hello.
How do you clear the content of a *.txt file?
Thanks.

Nov 21 '05 #3
I see.
Thanks very much, guys.

Xero
"Cor Ligthert" wrote:
Jeff,

Derek gave you the answer, however what he did not write in my opinon in
words was.

"Just create an empty one with the same name". (And than use one of his
samples)

Only meant as addition

Cor

"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )>
Hello.
How do you clear the content of a *.txt file?
Thanks.


Nov 21 '05 #4
"Xero" <jeff_@_chezjeff_._net(remove_underscores_and_this )> schrieb:
How do you clear the content of a *.txt file?


Open the file using 'FileStream' and use its 'SetLength' method to reset the
file's length.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

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

Similar topics

2
by: Jan | last post by:
I'm busy making a very basic and simple content management system wich stores the text in a .txt file. now i need to know how i can clear the ..txt file.. now it just adds the new text to the .txt...
2
by: Sure | last post by:
Hello Group, I have a php file which will list the pending task for each developer. If the developer changes some thing it will update to database. Once the user clicks the update button it...
4
by: Christian Otteneuer | last post by:
Hello Newsgroup, I have the following problem: I want to write a python script, that writes text into files. The text is being "collected" in a for-loop, the code looks like this: for i in...
3
by: Kyle Kolander | last post by:
I posted this in response to a previous thread but have not gotten any replies back... Hopefully someone has an answer? From looking at sections 27.7.3.2 and 27.7.1.2 of the standard, it appears...
4
by: aikwee | last post by:
how, how do i clear the current content of a datagrid? I am using datagrid to do a xml editor, so every time i try to open anther file and load it to datagrid, it actually append it in to...
4
by: Dhans | last post by:
Hi there, I am using log4net in my (.net v1.1) application to log the messages. I tried to clear the logfile while application is running. since log4net has the file handle it did not allow me to...
3
by: DHarry | last post by:
How can I clear a text file without deleting and creating a new (empty) file?
2
by: horneye | last post by:
After i use fstream to open a file, how can i use the fstream object to clear file's content?
3
by: ffrugone | last post by:
I am creating a blog and I have a problem which seems fairly common: Within the content of the posts I sometimes have floated images. The comments bar that follows each post will not clear the...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.