如何使用MONO Develop在Linux中用C#编写文本文件
Im使用ubto操作系统进行MONO开发,Im使用C#编程 我想写一个文本文件,但我不知道怎么写 我试过这个:如何使用MONO Develop在Linux中用C#编写文本文件,c#,linux,ubuntu,monodevelop,C#,Linux,Ubuntu,Monodevelop,Im使用ubto操作系统进行MONO开发,Im使用C#编程 我想写一个文本文件,但我不知道怎么写 我试过这个: string[] lines = {"some text1", "some text2", "some text3"}; System.IO.File.WriteAllLines(@"/home/myuser/someText.txt", lines); string str = "some text"; StreamWriter a = new StreamWriter("/ho
string[] lines = {"some text1", "some text2", "some text3"};
System.IO.File.WriteAllLines(@"/home/myuser/someText.txt", lines);
string str = "some text";
StreamWriter a = new StreamWriter("/home/myuser/someText.txt");
a.Write(str);
这不管用
我试过这个:
string[] lines = {"some text1", "some text2", "some text3"};
System.IO.File.WriteAllLines(@"/home/myuser/someText.txt", lines);
string str = "some text";
StreamWriter a = new StreamWriter("/home/myuser/someText.txt");
a.Write(str);
这也不管用
怎么办
tnx.两者都应该可以工作,也许您忘记提供应用程序代码了
using System;
using System.IO;
public class Program
{
public static int Main(string[] args)
{
string[] lines = {"some text1", "some text2", "some text3"};
File.WriteAllLines(@"/home/myuser/someText.txt", lines);
return 0;
}
}
使用
dmcs program.cs
编译,例如确保关闭流(File.close()或a.close(),我不熟悉c#语法),因为只有当流被释放时,它才实际写入文件 我没有收到错误消息。它将继续运行,但不会写入文件。我认为我写文本文件的方式是错误的。所以我想知道如何写。你写了文件后是否关闭或刷新了文件?你的方法还可以。还有别的问题。你已经知道如何写了@Amedio:这不适用于writeAllines案例第一种方法应该可以工作。第二种方法是忘记关闭流…这不是问题所在。mybe在linux上我应该用不同的方式来做,但我不知道这是在linux上,我的朋友。顺便问一句,你试过把你的前两行写进去吗?您可以很容易地看到它工作(除非,例如,目录丢失或您没有权限)