Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
最後にStreamWriterストリームに書き込んだ後、ファイルの内容を保存したい。
つまり、デフォルトでは StreamWriter の先頭にファイルパスを指定する必要がありますが、私はそうしたくありません。
最後に、つまりすべての行をストリームに書き込んだ後、コンテンツを保存するにはどうすればよいですか。
出来ますか?
を使用したさまざまなバリエーションがありますMemoryStream。
MemoryStream
using (var writer = new StreamWriter(new MemoryStream())) { writer.WriteLine("foo"); writer.Flush(); using (var file = File.Open("foo.txt")) { writer.BaseStream.Position = 0; writer.BaseStream.CopyTo(file); } }