Re: combine serveral .txt files



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.
>


.



Relevant Pages

  • Re: Send string to IP address
    ... "Plain hex" implies something formatted as text, but doesn't answer the question of encoding. ... There's no "just" as far as "an ASCII string" is concerned. ... Characters are not bytes and bytes are not characters. ... Normally you'd create the Writer once at the same time as you create the underlying stream, rather than every time you write some text, obviously. ...
    (comp.lang.java.programmer)
  • Re: Character semantics for filenames (was: win32 reading wide filenames (unicode))
    ... DO WITH CHARACTERS ABOVE "\xFF". ... suspect, openworks on the supplied byte stream AS IS, discregarding ... Unocode inserts hints in strings. ... encoding to perl strings by readdir and from perl strings to the OS ...
    (comp.lang.perl.misc)
  • Re: Stream and Encoding Confusion
    ... We are each writing programs to read an input file and count the number of ... a simple list that says we the program found so many of each character; ... treated as a character stream or a byte stream. ... I'm also somewhat concerned about encoding. ...
    (comp.lang.java.programmer)
  • RE: Object serialization and NetworkStream - extraneous characters in output
    ... when you retrieve the stream and try reading the ... you found there is an additional header "o;?" ... As for the problem you mentioned, I think it is likely due to the encoding ... ASCII stream won't have such a header). ...
    (microsoft.public.dotnet.framework)
  • Re: combine serveral .txt files
    ... encoding, for example) I'd just copy them as binary files: ... Open the first stream to read from ... When you've finished all the files, close the output stream. ...
    (microsoft.public.dotnet.languages.csharp)

Loading