0

I have filled up a List with many elements of "Hello".
Now I wonder how it is possible to use MemoryStream to "chunk" this and append it to an existing file.("C:\\OutFile.txt")
I have googled around on examples for 2 days without really understand how to do this.

I have understand that I need to write to memorystream and from here in somehow write from memorystream but it just leaves me with these words.

My beginning code is like follows. How can I do this ? Thank you.

List<String^>^ FillUp = gcnew List<String^>();
for (int i = 0; i < 1000000; i++) 
{ 
     FillUp->Add("Hello"); 
}

String^ OutPath = "C:\\OutFile.txt";

FileStream^ fs = gcnew FileStream(OutPath, FileMode::Append, FileAccess::ReadWrite); 
StreamWriter^ WriteToFile = gcnew StreamWriter(fs);

Edited by Lukezzz: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by __avd
0

FileAccess must be FileAccess:Write when FileMode::Append is used.

List<String^>^ FillUp = gcnew List<String^>();
	for (int i = 0; i < 10; i++){  
        FillUp->Add("Hello"); 
    }
    
 MemoryStream^ ms=gcnew MemoryStream();	
 for each(String^ s in FillUp){
    array<Byte>^ b=System::Text::Encoding::UTF8->GetBytes(s);
    ms->Write(b,0,b->Length);
 }

 String^ OutPath = "C:\\csnet\\OutFile.txt";
 FileStream^ fs = gcnew FileStream(OutPath, FileMode::Append,  
                                             FileAccess::Write); 
 ms->WriteTo(fs);
 fs->Flush();
 fs->Close();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.