记事本:
Hello world!
我如何将它放入 C# 并将其转换为字符串......?
到目前为止,我正在获取记事本的路径。
string notepad = @"c:\oasis\B1.text"; //this must be Hello world
请告诉我..我对此不熟悉.. tnx
最佳答案
您可以使用 File.ReadAllText()
方法读取文本:
public static void Main()
{
string path = @"c:\oasis\B1.txt";
try {
// Open the file to read from.
string readText = System.IO.File.ReadAllText(path);
Console.WriteLine(readText);
}
catch (System.IO.FileNotFoundException fnfe) {
// Handle file not found.
}
}
关于c# - 获取记事本的值并将其放入 c# 字符串中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6220318/