【问题标题】:StreamWriter does not create a file, working on OSXStreamWriter 不创建文件,在 OSX 上工作
【发布时间】:2016-08-03 10:30:55
【问题描述】:

我的代码有问题,

Xamarin 不会通知任何错误和警告,但文件仍未创建。

class MainClass
{
    public static void Main(string[] args)
    {
            int counter = 1;
            double init;
            double finish = 5.6;
            double step = 0.2;

        using (System.IO.StreamWriter file = new System.IO.StreamWriter("file.dat"))

        for (init = 1.0; init <= finish; init = init + step)
        {
            if (init / 2 < 1.5)
            {
                Console.WriteLine("init = " + init + "\t counter = " + counter + "\n");
                file.Write("init = " + init + "\t counter = " + counter + "\n");
                counter = counter + 1;
            }
            else
            {
                Console.WriteLine("Failed Expression at " + init + " in " + counter + " turn!\n");
                file.Write("init = " + init + "\t counter = " + counter + "\n");
                counter = counter + 1;

            }
        }


    }
}

我想在一个文件中写入与写入控制台相同的行,但该文件不存在。我检查了其他帖子并尝试了建议的解决方案变体,但文件仍然丢失。

【问题讨论】:

    标签: c# macos xamarin


    【解决方案1】:

    “test.dat”文件将被写入bin/Debugbin/Release 目录,因为您没有为该文件指定任何路径。

    示例输出:

    .
    ├── Program.cs
    ├── Properties
    │   └── AssemblyInfo.cs
    ├── TestFileOutput.csproj
    ├── TestFileOutput.csproj.user
    ├── bin
    │   └── Debug
    │       ├── TestFileOutput.exe
    │       ├── TestFileOutput.exe.mdb
    │       └── file.dat
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-30
      • 2017-01-21
      • 1970-01-01
      • 2010-11-12
      • 2015-09-02
      • 1970-01-01
      • 2015-06-05
      相关资源
      最近更新 更多