LoginSignup
3
5

More than 5 years have passed since last update.

C# ゼロバイトファイルの作成

Posted at

0byteファイルの作成方法

最近、テストでファイルを作成した時につまづいたのでそのメモ

最初は以下のように書いていました。しかしテストのcleanupで削除できない。

program.cs

System.IO.File.Create(@"hoge.txt");

CreateメソッドはStreamを返すのでCloseする必要がある。
以下のようにしたらうまくいきました。

program.cs

System.IO.File.Create(@"hoge.txt").Close();

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5