小弟在编写c#程序时需要创建一个文本文件,以便对其进行读取,但是编译总不行,我是这样写的:
..........
.........
....... Tom.txt:
Tiger
Monkey
前面都是代码,中间是我想添加的文本文件.我单独把它写在程序中了,老是通不过,请高手指点,谢谢!
..........
.........
....... Tom.txt:
Tiger
Monkey
前面都是代码,中间是我想添加的文本文件.我单独把它写在程序中了,老是通不过,请高手指点,谢谢!
using System.IO;class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
} // Open the file to read from.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
}
ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemIOFileClassCreateTextTopic.htm
consultant
programmer
就可以,所以我调试老是通不过.就按照我的意思应该怎么来写它,请高手再次帮忙