2016-08-03 81 views
-1

我的代碼存在問題,StreamWriter不創建文件,在OSX上工作

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; 

      } 
     } 


    } 
} 

我想在文件中寫入相同的行寫入控制檯,但該文件不存在。我檢查了其他帖子,並嘗試了各種解決方案,但該文件仍然丟失。

回答

0

「test.dat」文件將被寫入bin/Debugbin/Release目錄,因爲您未指定文件的任何路徑。

示例輸出:

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