Re: combine serveral .txt files
- From: "Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 17 Jan 2006 12:50:02 -0500
Sure. In that case, Jon's answer would be what you need to do. To quote Jon:
Unless you really care about them being text files (and changing the
encoding, for example) I'd just copy them as binary files:
1) Open a stream to write to
2) Open the first stream to read from
3) Read chunks at a time, writing to the output stream each time
4) When that file has been finished, close the stream and move onto
the next file (back to step 2)
5) When you've finished all the files, close the output stream.
Note that you should always use the return value from Stream.Read to
find out how many bytes have actually been read.
One possible caveat here: This technique will not work as is unless all of
the files are using the same encoding. Chances are, they are, but you should
make sure if they are not. If they are not the same encoding, you can
convert them to a common encoding on the fly if necessary.
If you're not sure all of the files have the same encoding, the following
article tells you how to detect the encoding of a file:
http://www.dotnet247.com/247reference/a.aspx?u=http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=469
Once you've detected the encoding, you will want to read the file into an
array of bytes, and convert it using the Encoding.Convert method. You can
then write the bytes to a File Stream. Keeping the File Stream open, you can
open, read, convert, and write each successive file to the new text file in
the same way until you're done.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
":)" <tao_benz@xxxxxxxxxxx> wrote in message
news:1137517645.558460.49950@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Thanks for your answer. My requirement is combine servral .txt file
> into one .txt files.
>
.
- References:
- combine serveral .txt files
- From: :)
- Re: combine serveral .txt files
- From: Kevin Spencer
- Re: combine serveral .txt files
- From: Jon Skeet [C# MVP]
- Re: combine serveral .txt files
- From: Kevin Spencer
- Re: combine serveral .txt files
- From: :)
- combine serveral .txt files
- Prev by Date: RE: Using property to access elements of array?
- Next by Date: Re: C# XML Crystal Reports
- Previous by thread: Re: combine serveral .txt files
- Next by thread: Re: combine serveral .txt files
- Index(es):
Relevant Pages
|
Loading