我的代码有问题,
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 :(得分:0)
&#34; test.dat&#34;文件将写入bin/Debug
或bin/Release
目录,因为您没有指定文件的任何路径。
示例输出:
.
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── TestFileOutput.csproj
├── TestFileOutput.csproj.user
├── bin
│ └── Debug
│ ├── TestFileOutput.exe
│ ├── TestFileOutput.exe.mdb
│ └── file.dat