Im using Ubunto OS with MONO Develop and Im programming with C#.
I want to write into a text file but I dont sure how to do it.
I tried this:
string[] lines = {"some text1", "some text2", "some text3"};
System.IO.File.WriteAllLines(@"/home/myuser/someText.txt", lines);
this didn't work.
I tried this:
string str = "some text";
StreamWriter a = new StreamWriter("/home/myuser/someText.txt");
a.Write(str);
this didn't work too.
what to do?
tnx.
Both should work, perhaps you forgot to provide the application code?
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;
}
}
Compile with dmcs program.cs
, eg
确保关闭流(File.Close()或a.Close(),我对c#语法不熟悉),因为只有当流被处理时,它实际上才写入文件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.